系统应用程序未收到广播的意图
问题描述:
我有一个BroadcastReciever
在系统应用程序中,我想发送一个Intent
(用于测试目的,因为我正在修改该系统应用程序)。系统应用程序未收到广播的意图
该系统应用程序的AndroidManifest.xml
看起来是这样的:
<application android:label="@string/app_name">
<receiver android:label="StateReceiver" android:name=".abstractor.StateReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.sec.android.contextaware.HEADSET_PLUG" />
<action android:name="android.intent.action.LOCALE_CHANGED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<provider android:name=".manager.LoggingDataProvider" android:authorities="com.sec.android.contextaware.manager.LoggingDataProvider" />
</application>
我用一个测试应用程序,并检查目标系统的应用程序确实可以接收该意图:
Intent intent = new Intent();
intent.setAction("com.sec.android.contextaware.HEADSET_PLUG");
PackageManager pm = getPackageManager();
for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(bt, 0)) {
Log.d("APP: ", resolveInfo.toString());
}
,并取回与系统应用程序的信息一ResolveInfo
,所以它应该能够接受的意图。然后我播出了意图:
sendBroadcast(intent);
但是没有任何反应,意图没有收到。我完全控制了目标系统应用程序的清单文件和代码。是否有可能以某种方式获得意图? 设备已生根。
答
你试过sendStickyBroadcast(intent)吗?注册一个空接收器后,你应该能够检索最后发送的一个。不确定它会有帮助。顺便说一句,你发送给目标系统的应用程序是什么?它没有到达那里,因为它不允许或因为你正在解决它的方式有什么问题:intent.setAction(“com.sec.android.contextaware.HEADSET_PLUG”);
我猜测com.sec.android.contextaware.HEADSET_PLUG没有权限允许接收或寻址不正确。仔细检查com.sec.android.contextaware.HEADSET_PLUG。
目标是ContextAwareService.apk,一种三星服务,它监听某些事件并在通知栏中显示内容。明天将尝试你的建议,现在睡觉的时间。 ;) – rickythefox 2012-07-12 22:36:17
没有工作。上面的AndroidManifest.xml来自目标,不应该能够从任何人那里接收“com.sec.android.contextaware.HEADSET_PLUG”吗? – rickythefox 2012-07-13 09:48:53