0
我嘗試執行BroadcastReceiver
的許可方式。Android廣播 - 有權限發送和接收
在發件人類,我試圖發送一個正常的廣播
Intent intent = new Intent();
intent.setAction("com.vn.BroadcastReceiver");
intent.putExtra("Foo", "Bar");
sendBroadcast(intent);
與AndroidManifest
文件
<uses-permission android:name="com.nhp"/>
在接收機類,我寫了一個自定義的FirstBroadcastReceiver
public class FirstBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = FirstBroadcastReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive: " + intent.getStringExtra("Foo"));
}
}
及其AndroidManifest
<permission android:name="com.nhp" />
<receiver
android:permission="com.nhp"
android:exported="true"
android:name=".receivers.FirstBroadcastReceiver">
<intent-filter>
<action android:name="com.vn.BroadcastReceiver" />
</intent-filter>
</receiver>
我安裝接收機應用第一和發件人然後。它的工作!
但是當我嘗試撥打sendBroadcast(intent,"com.nhp");
時,它從不觸發任何事情。任何人都可以爲我解釋爲什麼?謝謝
太棒了!謝謝 –