2011-12-28 208 views
1

任何人都可以共享示例代碼來啓動/啓動設備時如何啓動android應用程序?如何在啓動設備時啓動應用程序?

+1

精確複製http://stackoverflow.com/questions/6391902/how-to-start-an-application-on-startup – 2011-12-28 10:47:50

回答

1

此代碼將在啓動時啓動應用程序。你需要聽取ACTION_BOOT_COMPLETE

in AndroidManifest.xml (application-part): 

<receiver android:enabled="true" android:name=".BootUpReceiver" 
     android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> 

     <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
</receiver> 
[..] 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
[..] 

public class BootUpReceiver extends BroadcastReceiver{ 

     @Override 
     public void onReceive(Context context, Intent intent) { 
       Intent i = new Intent(context, MyActivity.class); 
       i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       context.startActivity(i); 
     } 

} 
+0

感謝您的幫助:) – piks 2011-12-29 12:56:02

相關問題