手机开机时自动启动应用程序

4

如何让我的应用程序在手机自启动时启动。


3
你有没有尝试过谷歌搜索?http://www.androidsoftwaredeveloper.com/2009/03/20/how-to-start-on-boot/ - fredley
重复的问题(其中之一):如何自动启动Android应用程序? - Christopher Orr
1个回答

11
你需要使用一个带有 android.intent.action.BOOT_COMPLETED intent 的 BroadcastReceiver
在你的清单文件中添加以下内容:
<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类实现了BroadcastReceiver。实现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 
    }
}

非常感谢大家,你们的意见肯定会帮我找到我正在寻找的解决方案...非常感谢... - Nandagopal T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接