1

如何让 Android 应用程序在手机重启时自动重启。我为android制作了一个应用程序,现在我希望它会在手机重启时自动重启,有人可以帮我解决这个问题吗?

4

3 回答 3

0
<receiver android:name=".BootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
于 2012-08-22T11:35:50.613 回答
0

来自http://www.anddev.org/launch_activity_on_system-emulator_startup-t428.html

在清单中

  <receiver class=".MyStartupIntentReceiver">

            <intent-filter>

                 <action android:value="android.intent.action.BOOT_COMPLETED" />

                 <category android:value="android.intent.category.HOME" />

            </intent-filter>

        </receiver> 

MyStartupIntentReceiver 类:

public class MyStartupIntentReceiver extends IntentReceiver {



        @Override

        public void onReceiveIntent(Context context, Intent intent) {

                /* Create intent which will finally start the Main-Activity. */

                Intent myStarterIntent = new Intent(context, LaunchOnStartup.class);

                /* Set the Launch-Flag to the Intent. */

                myStarterIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);

                /* Send the Intent to the OS. */

                context.startActivity(myStarterIntent);

        }

}
于 2012-08-22T11:57:27.463 回答
0

你可以使用 BroadcastReceiver 来监听 BOOT_COMPLETED 广播并做你想做的事。

于 2012-08-22T11:32:51.050 回答