0
我想實現的是趕上啓動完成事件的廣播接收機。引導接收器不工作
我把權限在manifet
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
我把意圖過濾清單中的接收器標籤後(類文件是在接收包)
<receiver android:name=".receivers.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
最後我宣佈接收者類。該類應從數據庫加載一些數據並設置警報。然而爲了檢查它是否有效,我已經放了一個吐司,但它沒有顯示和振動。
public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent callingIntent) {
Vibrator vibrator=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(5000);
Toast.makeText(context, "BOOT RECEIVED", Toast.LENGTH_LONG).show();
}
}
有人知道爲什麼請嗎?
+1有趣的解釋 - 我只是想回答說你需要先運行應用程序,然後才能收到它。尼斯。 –
謝謝。 BTW預裝的應用程序不會去的/data/system/packages-stopped.xml,因此所有的人都能夠接受的事件。此外,應用程序的強制停止使該應用程序進入該文件,意味着停止狀態。 –