2010-09-01 177 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

相关问题