だから私は確かに私の質問に対する答えを徹底的に探しました。通常、私はほとんど何に対しても非常に簡単に答えを見つけることができます。
とにかく、基本的に私は最終的に放送受信機を設定するアラームマネージャーを設定しています。受信者の内部では、受信したインテントを決定し、共有設定を削除してから、アクティビティを開始する通知を設定します。問題は、4.0を搭載した電話では共有設定項目が正常に削除されないことですが、以前に試した電話(2.2、2.3)では完全に機能します。
私はAndroid3.1とFLAG_INCLUDE_STOPPED_PACKAGES実装のドキュメントを見つけることになりました。念のため、それをインテントに投げてみましたが、それでも機能しませんでした。いずれにせよ、問題となるのはアクティビティの起動ではなく、共有設定の単純な削除です。
それが十分に明確であることを願っています!以下のコードのいくつかを入力します。
ここからインテントが開始されます。
Calendar cal = Calendar.getInstance();
int seconds = 5 * 60; // 1 * 24 * 60 * 60;
cal.add(Calendar.SECOND, seconds);
Intent intent = new Intent(SetAlertActivity.this, ReminderReceiver.class);
intent.putExtra("id", "FAlert");
//intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), FRAUD_ALERT_CODE, intent, 0);
AlarmManager alertManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alertManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
settingsEditor = alertSettings.edit();
settingsEditor.putLong("AlertTime1", cal.getTimeInMillis());
settingsEditor.commit();
そして、ブロードキャストレシーバーonReceive():
nContext = context;
alertSettings = nContext.getSharedPreferences(MainActivity.PREFERENCE_FILENAME, 0);
if (intent.getStringExtra("id").equals("FAlert"))
{
settingsEditor = alertSettings.edit();
settingsEditor.remove("AlertTime1");
settingsEditor.commit();
String ns = Context.NOTIFICATION_SERVICE;
int icon = R.drawable.ar_icon;
CharSequence tickerText = nContext.getString(R.string.notification_ticker);
CharSequence contentTitle = nContext.getString(R.string.notification_title);
CharSequence contentText = nContext.getString(R.string.notification_text);
long when = System.currentTimeMillis();
NotificationManager mNotificationManager = (NotificationManager) nContext.getSystemService(ns);
Notification notification = new Notification(icon, tickerText, when);
Intent notificationIntent = new Intent(nContext, SetAlertActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(nContext, 135, notificationIntent, 0);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(nContext, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
したがって、前述したように、4.0のデバイス(3.Xデバイスはありません)では、
settingsEditor = alertSettings.edit();
settingsEditor.remove("AlertTime1");
settingsEditor.commit();
一部が機能していません。アクティビティは正しく開きますが、「AlertTime1」はまだそこにあります。2.2および2.3デバイスでは、「AlertTime1」は正常に削除されます。
ため息:D
助けてくれてありがとう!
ああ、そしてそれが必要な場合に備えて、これが受信者のための私のマニフェストです:
<receiver
android:name="ReminderReceiver"
android:process=":remote" >
</receiver>
これが違いを示しています。
alertSettings = getSharedPreferences(AlertRenewActivity.PREFERENCE_FILENAME, 0);
settingsEditor = alertSettings.edit();
if (alertSettings.contains("AlertTime1"))
{
alertTime = alertSettings.getLong("AlertTime1", 0);
timeLeft = (int) ((alertTime - System.currentTimeMillis()) / (1000L));
daysLeft = timeLeft / (60 * 60 * 24);
daysLeftView.setText(Integer.toString(daysLeft));
setAlert.setEnabled(false);
setAlert.setTextColor(R.color.dark_text);
}
else
{
daysLeftView.setText(R.string.no_alert_set);
}
古い電話では、「アラートセットなし」と正しくリセットされますが、4.0電話では、残り0日が表示されます(テスト用にアラートを5分程度に設定しているだけなので、これが表示されます) 。基本的に、正しくリセットされていないため、ユーザーは新しいアラートを設定できません。また、私が試している4.0の電話でのみ:P