自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android開機(jī)自啟動(dòng)具體操作方法簡(jiǎn)介

移動(dòng)開發(fā) Android
Android開機(jī)自啟動(dòng)可以通過定義一個(gè)BroadcastReceiver;配置Receiver的許可等方式來(lái)實(shí)現(xiàn)。在這里就對(duì)這些步驟進(jìn)行一個(gè)詳細(xì)介紹。

在模擬器中對(duì)Android 操作系統(tǒng)進(jìn)行相應(yīng)的編寫,可以幫助我們實(shí)現(xiàn)應(yīng)用程序的開機(jī)自啟動(dòng)功能。在這里我們就來(lái)通過一段代碼充分的掌握Android開機(jī)自啟動(dòng)的相關(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)啟動(dò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)啟動(dòng)消息,在AndroidManifest.xml中

Android開機(jī)自啟動(dòng)的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.啟動(dòng)模擬器,可以看到系統(tǒng)啟動(dòng)后,彈出一個(gè)對(duì)話框。

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

【編輯推薦】

  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)方式簡(jiǎn)介 
  5. Android HelloWord編寫方式介紹 
責(zé)任編輯:曹凱 來(lái)源: javaeye.com
相關(guān)推薦

2009-12-30 16:48:52

Silverlight

2010-01-28 16:14:33

Android安裝卸載

2010-04-02 08:42:32

Oracle 游標(biāo)

2010-02-03 13:26:53

C++計(jì)時(shí)

2010-02-02 17:13:35

C++ Endian

2010-01-07 15:37:35

VB.NET ForNext循環(huán)

2010-02-02 13:57:31

C++解析#pragm

2010-04-13 17:00:27

Oracle NLS_

2010-03-05 15:27:06

Python文件路徑

2010-02-02 16:23:46

C++實(shí)現(xiàn)WPF動(dòng)畫

2010-08-02 17:20:12

nfs啟動(dòng)Linux

2010-07-26 13:30:23

2010-03-19 14:19:58

Python正則表達(dá)式

2010-03-05 17:06:26

Python顯示UTF

2009-12-30 15:47:40

Silverlight

2011-03-17 09:06:58

iptables映射端口

2009-12-31 15:36:13

SilverLight

2009-12-31 15:36:13

SilverLight

2010-08-02 12:34:09

ADSL代理設(shè)置

2010-01-15 15:51:43

VB.NET類添加方法
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)