日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android開機(jī)自啟動具體操作方法簡介

在模擬器中對Android 操作系統(tǒng)進(jìn)行相應(yīng)的編寫,可以幫助我們實(shí)現(xiàn)應(yīng)用程序的開機(jī)自啟動功能。在這里我們就來通過一段代碼充分的掌握Android開機(jī)自啟動的相關(guān)實(shí)現(xiàn)方法,以幫助大家掌握這一應(yīng)用。

1.定義一個(gè)BroadcastReceiver

Java代碼

 
 
 
  1. public class BootReceiver extends BroadcastReceiver {   
  2. public void onReceive(Context ctx, Intent intent) {   
  3. Log.d("BootReceiver", "system boot completed");   
  4. //start activity   
  5. String action="android.intent.action.MAIN";   
  6. String category="android.intent.category.LAUNCHER";   
  7. Intent myi=new Intent(ctx,CustomDialog.class);   
  8. myi.setAction(action);   
  9. myi.addCategory(category);   
  10. myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
  11. ctx.startActivity(myi);   
  12. //start service   
  13. Intent s=new Intent(ctx,MyService.class);   
  14. ctx.startService(s);   
  15. }   
  16. }   
  17. public class BootReceiver extends BroadcastReceiver {  
  18. public void onReceive(Context ctx, Intent intent) {  
  19. Log.d("BootReceiver", "system boot completed");  
  20. //start activity  
  21. String action="android.intent.action.MAIN";  
  22. String category="android.intent.category.LAUNCHER";  
  23. Intent myi=new Intent(ctx,CustomDialog.class);  
  24. myi.setAction(action);  
  25. myi.addCategory(category);  
  26. myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  27. ctx.startActivity(myi);  
  28. //start service  
  29. Intent s=new Intent(ctx,MyService.class);  
  30. ctx.startService(s);  
  31. }  

2.配置Receiver的許可,允許接收系統(tǒng)啟動消息,在AndroidManifest.xml中:

Xml代碼

 
 
 
  1. < uses-permission android:name=
    "android.permission.RECEIVE_BOOT_COMPLETED"/>   
  2. < uses-permission android:name=
    "android.permission.RECEIVE_BOOT_COMPLETED"/> 

3.配置Receiver,可以接收系統(tǒng)啟動消息,在AndroidManifest.xml中

Android開機(jī)自啟動的Xml代碼

 
 
 
  1. < receiver android:name=".app.BootReceiver">   
  2. < intent-filter>   
  3. < action android:name="android.intent.action.BOOT_COMPLETED"/>   
  4. < category android:name="android.intent.category.HOME" />   
  5. < /intent-filter>   
  6. < /receiver>   
  7. < receiver android:name=".app.BootReceiver"> 
  8. < intent-filter> 
  9. < action android:name="android.intent.action.BOOT_COMPLETED"/> 
  10. < category android:name="android.intent.category.HOME" /> 
  11. < /intent-filter> 
  12. < /receiver> 

4.啟動模擬器,可以看到系統(tǒng)啟動后,彈出一個(gè)對話框。

Android開機(jī)自啟動的具體方法就為大家介紹到這里。

【編輯推薦】

  1. Android顯示網(wǎng)絡(luò)圖片相關(guān)實(shí)現(xiàn)方法淺談 
  2. Android應(yīng)用技巧總結(jié) 
  3. Android Theme詳細(xì)內(nèi)容概述 
  4. Android重力感應(yīng)實(shí)現(xiàn)方式簡介 
  5. Android HelloWord編寫方式介紹 

名稱欄目:Android開機(jī)自啟動具體操作方法簡介
網(wǎng)站網(wǎng)址:http://m.5511xx.com/article/cdideos.html