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 等其他手机。任何人请告诉我在这里做什么。我有点卡住了..