3

谁能给我自动在android设备上运行android应用程序的代码或链接或概念。每当设备打开时,应用程序应该自行启动,而不受用户的干扰。

谢谢..

4

1 回答 1

4

您需要声明一个广播监听器来监听 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);

使用上述想法的另一个示例:自动启动应用程序

于 2010-07-28T14:03:54.883 回答