如何自动运行一个应用程序时,手机处于开机状态应用程序、自动运行、状态、手机

2023-09-12 05:14:44 作者:祖国滴花骨朵°

任何人都可以请您给我code或链接或概念的自动运行在Android设备中的android应用..只要设备处于开机状态,应用程序应该自行启动,与出用户的干扰。

Can anyone please give me code or links or concept for running an android application on android device automatically.. whenever the device is switched on, application should start on its own, with out the interference of the user.

感谢你..

推荐答案

您需要声明一个广播监听器监听RECEIVE_BOOT_COMPLETED

You need to declare a broadcast listener that listens for RECEIVE_BOOT_COMPLETED

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

在你的监听器:

Intent myStarterIntent = new Intent(context, YOUR_CLASS_TO_START.class);
/* Set the Launch-Flag to the Intent. */
myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myStarterIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
/* Send the Intent to the OS. */
context.startActivity(myStarterIntent);

另一个例子使用了上述观点:自动启动应用

 
精彩推荐
图片推荐