-3
A
回答
0
以下代碼適用於我!希望會對你有所幫助。
的AndroidManifest.xml
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service android:name="NotifyingDailyService" >
</service>
BootCompletedReceiver.class
public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.w("boot_broadcast_poc", "starting service...");
context.startService(new Intent(context, NotifyingDailyService.class));
}
}
硒rvice.class
public class NotifyingDailyService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent pIntent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "NotifyingDailyService", Toast.LENGTH_LONG).show();
Log.i("com.example.bootbroadcastpoc","NotifyingDailyService");
return super.onStartCommand(pIntent, flags, startId);
}
}
+0
其工作正常謝謝! – Puri
相關問題
- 1. 打開/關閉Android設備
- 2. 打開系統位置設置後,android對話框不會關閉
- 3. android:檢測設置(com.android.settings)是否打開
- 4. 當設備關閉
- 5. 在Chrome中打開或關閉設備仿真模式時進行檢測
- 6. 檢測設備是否關閉?
- 7. 當設備關閉並再次打開時,鬧鐘在android中不起作用
- 8. 檢測圓括號,打開和關閉
- 9. 檢測當我打開一個窗口關閉 - js
- 10. 檢測Android設備
- 11. 無法檢測到用戶在Android設備上的當前位置
- 12. 關閉並重新打開後,如何在後臺重新連接BLE設備?
- 13. 檢測網站的打開位置從
- 14. 軟件設計:數據庫打開和關閉的位置
- 15. JavaScript - 打開開關,然後關閉
- 16. 檢測移動設備中當前的地理位置
- 17. MFMailComposeViewController打開然後關閉
- 18. Google地圖力量關閉GPS位置和半徑檢測(Android)
- 19. Xamarin Android設置開關位置
- 20. android vibrator打開和關閉
- 21. 打開一個文件(以後將其關閉)僅當標誌設置
- 22. 當Android設備處於飛行模式時,打開位置提示失敗
- 23. 當設備打開時打開android應用程序
- 24. Android中的鬧鐘設置關閉和打開
- 25. 如何在位置設置中打開/關閉「使用無線網絡」?
- 26. 在關閉時與當已經打開
- 27. 關閉頁面的位置元素,然後檢索位置()
- 28. 檢查設備的當前位置(位置)是否在某個特定位置
- 29. 關閉設備屏幕在android
- 30. 在android中關閉設備的事件
請張貼一些代碼,確保您註冊的是BroadcastReceiver。 – Phillen
其實我不知道如何檢測設備開機狀態 – Puri
你的意思是說..你想在Android設備打開時運行廣播嗎? – Naitik