0
ここに私のコードです。アンドロイドでの通知の問題を伴うアラームの生成
Calendar cal = Calendar.getInstance();
int id = (int) cal.getTimeInMillis();
Intent myIntent = new Intent(this,MyScheduledReceiver.class);
myIntent.putExtra("taskTitle", taskTitle.getText().toString());
myIntent.putExtra("taskDetails", taskDetails.getText().toString());
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(year, mon, day,tp.getCurrentHour(),tp.getCurrentMinute());
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), id,
myIntent,PendingIntent.FLAG_UPDATE_CURRENT| Intent.FILL_IN_DATA);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
..私はプログラム的にアラームを生成することはできませんよどこから 私は、ブロードキャストレシーバにアン
<receiver android:name=".MyScheduledReceiver"></receiver>
マニフェストファイルで
を宣言しました。NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager manger = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "Combi Note",
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID,
new Intent(context, MyScheduledReceiver.class), 0);
Bundle extras=intent.getExtras();
String title=extras.getString("taskTitle");
String note=extras.getString("taskDetails");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
manger.notify(NOTIFICATION_ID++, notification);
私はちょっと混乱しています - アラームを生成することができないと言いましたが、これはReceiverのonReceive(...)が呼び出されないことを意味します。これは本当ですか? – Nick
私はそれが正しい方法であるよりも通知をgenerizeしたい場合は残してください...それはリマインダの一種です..私はあなたの意見を持っていると思います。 2012年3月17日午後7時に仕事の例を通知 –
私はあなたのアラームコードに明白なエラーがないので、あなたが設定しているアラーム時刻のような何かがあなたが期待しているものではない、簡単にするために、私はあなたのレシーバーのonReceive(...)の内部にトーストメッセージを表示するだけです。また、あなたのcal.set(...)呼び出しをコメントアウトし、cal.setTimeInMillisをcal.setTimeInMillis(System.currentTimeMillis()+ 5000)に変更します。そのため、アプリを実行するときに、Toastメッセージが表示されない場合は、起動していないことがわかります。 – Nick