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等其他手機。任何人都可以告訴我該怎麼做。我有點卡住..ALERT_BOOT_COMPLETED在某些手機中沒有收到,但工作得很好,否則
我已經在我的接收器中添加了清單和意圖篩選器操作中的所有權限... – 2013-04-09 22:09:05