一个app启动时,通过发送一个广播,唤醒其他app。如何 进一步区别 接受着呢?通过自定义权限。
public void click(View v) { Intent in = new Intent("com.text.demo1.MyReceiver"); //sendBroadcast(in); //指定 接受权限的 广播,接收者必须 拥有该权限否则无法接受 String reqPerm = "com.text"; sendBroadcast(in, reqPerm); } 如下 是一个广播接收者 <!--声明自定义权限--> <permission android:name="com.text" /> <!--使用自定义权限--> <uses-permission android:name="com.text" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MyReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.text.demo1.MyReceiver"></action> </intent-filter> </receiver> </application>