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 からサービスを開始しています。このコードは、Samsung SII などの一部の携帯電話では機能しますが、Sony Xperia Neo などの他の携帯電話では機能しません。ここで何をすべきか教えてください。私はちょっと立ち往生しています..