Android開機啟動應用和服務
注冊廣播監聽開機狀態,啟動應用和服務等;
監聽開機的廣播接收器:
public class BootCompletedReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//開機啟動服務
Intent it= new Intent("com.test.action.testservice");
context.startService(it);
//啟動應用
Intent act= new Intent("com.test.action.testactivity");
context.startActivity(act);
}
}
在Manifest.xml中注冊監聽開機的廣播:
<receiver android:name="com.test.BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
添加開機狀態的權限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!