0
public class AlertBootCompletedReceiver extends BroadcastReceiver {

    private PackageManager pm;
    private boolean isStoredExternally;

    @Override
    public void onReceive(Context context, Intent arg1) {
        // TODO Auto-generated method stub

        pm = context.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            ApplicationInfo ai = pi.applicationInfo;
            isStoredExternally = (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE;

        } catch (NameNotFoundException e) {
            // do something
        }
        if (arg1.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

            if (!isStoredExternally) {
                // I start a service here
            }
        }
        if (arg1.getAction().equals(
                Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
                && isStoredExternally) {

            // I start a service here ..
        }

    }

}

我通过接收 ALERT_BOOT_COMPLETED 从我的 BroadCastReceiver 启动服务。此代码在三星 SII 等某些手机上适用于我,但不适用于索尼 Xperia Neo 等其他手机。任何人请告诉我在这里做什么。我有点卡住了..

4

1 回答 1

1

工作设备可能是 3.1 之前的情况。如果我没记错的话,在 3.1BOOT_COMPLETED之后,只有在用户第一次打开应用程序之后才会处理广播。

检查这篇博文

于 2013-04-09T22:07:15.190 回答