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等其他手机上工作..任何人请告诉我该怎么做。我有点卡住..
答案 0 :(得分:1)
可能的情况是工作装置是3.1之前的。如果我没记错的话,3.1之后只会在用户第一次打开应用程序后处理BOOT_COMPLETED
广播。