我需要我的应用程序在手机重新启动并开机后自动启动一次。
我使用了AutoStart an Application at boot up提供的代码,现在我的android应用程序在手机重启(重启)后自动启动。
现在,考虑一下,我使用了phone power off(关机)选项,而不是重新启动手机。手机开机后,我的应用程序不会按预期自动启动。你能解释一下我错过了什么吗?

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

<receiver android:enabled="true" android:name=".BootUpReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>



public class BootUpReceiver extends BroadcastReceiver
{
    private static SharedPreferences aSharedSettings;

    @Override
    public void onReceive(Context context, Intent intent)
    {
        aSharedSettings = context.getSharedPreferences("MYPreferences", Context.MODE_PRIVATE);
        boolean isUserLoggedIn = aSharedSettings.getBoolean(kEY.AUTHENTICATED, false);
        if(isUserLoggedIn)
        {
Intent aServiceIntent = new Intent(context, HomeView.class);
                aServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(aServiceIntent);
}

    }
}

谢谢您。

最佳答案

如果您在重新启动手机之前至少手动启动一次应用程序,而不是“强制关闭”它,那么它是否按预期工作?
看看:
Android : android.intent.action.BOOT_COMPLETED on ICS and Gingerbread
Boot Completed Regression Confirmed

07-24 09:47
查看更多