十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本篇文章為大家展示了Android中怎么實(shí)現(xiàn)開機(jī)自啟動(dòng),內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
站在用戶的角度思考問題,與客戶深入溝通,找到宜秀網(wǎng)站設(shè)計(jì)與宜秀網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋宜秀地區(qū)。
1.定義一個(gè)BroadcastReceiver
Java代碼
public class BootReceiver extends BroadcastReceiver { public void onReceive(Context ctx, Intent intent) { Log.d("BootReceiver", "system boot completed"); //start activity String action="android.intent.action.MAIN"; String category="android.intent.category.LAUNCHER"; Intent myi=new Intent(ctx,CustomDialog.class); myi.setAction(action); myi.addCategory(category); myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(myi); //start service Intent s=new Intent(ctx,MyService.class); ctx.startService(s); } } public class BootReceiver extends BroadcastReceiver { public void onReceive(Context ctx, Intent intent) { Log.d("BootReceiver", "system boot completed"); //start activity String action="android.intent.action.MAIN"; String category="android.intent.category.LAUNCHER"; Intent myi=new Intent(ctx,CustomDialog.class); myi.setAction(action); myi.addCategory(category); myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(myi); //start service Intent s=new Intent(ctx,MyService.class); ctx.startService(s); } }
2.配置Receiver的許可,允許接收系統(tǒng)啟動(dòng)消息,在AndroidManifest.xml中:
Xml代碼
< uses-permission android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"/>< uses-permission android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"/>
3.配置Receiver,可以接收系統(tǒng)啟動(dòng)消息,在AndroidManifest.xml中
Android開機(jī)自啟動(dòng)的Xml代碼
< receiver android:name=".app.BootReceiver"> < intent-filter> < action android:name="android.intent.action.BOOT_COMPLETED"/> < category android:name="android.intent.category.HOME" /> < /intent-filter> < /receiver> < receiver android:name=".app.BootReceiver"> < intent-filter> < action android:name="android.intent.action.BOOT_COMPLETED"/> < category android:name="android.intent.category.HOME" /> < /intent-filter> < /receiver>
上述內(nèi)容就是Android中怎么實(shí)現(xiàn)開機(jī)自啟動(dòng),你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。