2010-09-01 174 views
4

如何讓我的應用程序在我的手機啓動時自動啓動。手機啓動時自動啓動應用程序

+3

你甚至試過Google嗎? http://www.androidsoftwaredeveloper.com/2009/03/20/how-to-start-on-boot/ – fredley 2010-09-01 12:53:10

+0

複製(其中包括):[如何自動啓動Android應用程序?](http:// stackoverflow。 com/questions/1056570/how-to-autostart-an-android-application) – 2010-09-01 15:21:10

回答

10

您需要使用BroadcastReceiverandroid.intent.action.BOOT_COMPLETED意圖。

添加下列內容清單文件:

<receiver android:name="MyApp_Receiver"> 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</receiver> 

MyApp_Receiver類實現BoradcastReciever。實施onReceive()方法並從您的應用程序開始您最喜歡的活動。

public void onReceive(Context context, Intent intent) { 
    // make sure you receive "BOOT_COMPLETED" 
    if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))) 
    { 
     // Start the service or activity 
    } 
} 
+0

非常感謝你們,你們的投入肯定會找到我想要的解決方案......非常感謝... – 2010-09-01 13:22:04

+1

然後標記答案已被接受 – droidgren 2010-09-02 14:21:05

相關問題