Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android O中未调用具有签名权限的Android隐式广播接收器_Android_Broadcastreceiver_Android 8.0 Oreo_Android Implicit Intent - Fatal编程技术网

在Android O中未调用具有签名权限的Android隐式广播接收器

在Android O中未调用具有签名权限的Android隐式广播接收器,android,broadcastreceiver,android-8.0-oreo,android-implicit-intent,Android,Broadcastreceiver,Android 8.0 Oreo,Android Implicit Intent,在我的第一个应用程序中,我在清单文件中定义了自定义权限和隐式BroadcastReceiver: <permission android:name="com.example.test.TEST" android:protectionLevel="signature" /> <receiver android:name=".TestBroadcastReceiver"

在我的第一个应用程序中,我在清单文件中定义了自定义权限和隐式
BroadcastReceiver

<permission
        android:name="com.example.test.TEST"
        android:protectionLevel="signature" />

<receiver
        android:name=".TestBroadcastReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="com.example.test.TEST">
        <intent-filter>
                <action android:name="com.example.test.TEST_RECEIVER" />
        </intent-filter>
</receiver>
<uses-permission android:name="com.example.test.TEST" />
在我的第二个应用程序中,我在清单文件中添加了权限:

<permission
        android:name="com.example.test.TEST"
        android:protectionLevel="signature" />

<receiver
        android:name=".TestBroadcastReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="com.example.test.TEST">
        <intent-filter>
                <action android:name="com.example.test.TEST_RECEIVER" />
        </intent-filter>
</receiver>
<uses-permission android:name="com.example.test.TEST" />
但在第一个应用程序中没有调用任何内容。我知道我们不能在android O及以上版本中使用隐式广播,但根据,对于需要签名许可的广播有一个例外:

需要签名许可的广播不受此限制 限制,因为这些广播仅发送给 使用相同的证书签名,而不是设备上的所有应用


那么,我如何在android O中向我的其他应用发送信号呢?

根据Commonware的回答,问题是我缺少
setPackage()
部分。因此,我将代码更改如下,现在接收到广播:

getActivity().sendBroadcast(new Intent("com.example.test.TEST_RECEIVER").setPackage("com.example.test"));

由于这些都在您自己的应用程序中,请使用明确的
意图。还要注意的是,您需要保证第一个应用程序总是在第二个应用程序之前安装,以使
签名
权限生效。@Commonware,我用
新的意图(“com.example.test.TestBroadcastReceiver”).setPackage(“com.example.test”)
,但问题仍然存在。您修改的
意图
操作与
中的操作字符串不匹配。使用原始的
Intent
操作加上
setPackage(“com.example.test”)
部分,或者使用
新的Intent(context,TestBroadcastReceiver.class)
(如果
TestBroadcastReceiver
与广播发送方在同一个应用程序中)。