android 广播、service自定义权限

步骤(我们以广播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、清单配置文件声明权限:
 
            
        

应用B

3、在清单配置文件中声明如下权限:

    
4、在代码中发送广播:
 Intent intent = new Intent();
                intent.setAction("com.test.huawei");
                sendBroadcast(intent);

你可能感兴趣的:(android 广播、service自定义权限)