步骤(我们以广播broadcastReceiver为例)
应用A
1、新建class,继承BroadcastReceiver,如下:
public class TestRece extends BroadcastReceiver {
private static final String TAG = "TestRece";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive: ");
}
}
2、清单配置文件声明权限:
<receiver android:name="XXX.TestRece"
android:permission="com.permission.test>
<intent-filter>
<action android:name="com.test.huawei"/>
</intent-filter>
</receiver>
应用B
3、在清单配置文件中声明如下权限:
<permission android:name="com.permission.test" android:protectionLevel="normal"/>
<uses-permission android:name="com.permission.test"/>
4、在代码中发送广播:
Intent intent = new Intent();
intent.setAction("com.test.huawei");
sendBroadcast(intent);
网友评论