-1

特定の日時に発生する通知を作成しようとしています。

public void notify(View v){
  Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.DAY_OF_WEEK, 2);
  calendar.set(Calendar.HOUR_OF_DAY, 8);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
    mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
      final Notification notifyDetails = new Notification(R.drawable.android_logo,"New Alert, Click Me!",calendar);
    Context context = getApplicationContext();
      CharSequence contentTitle = "Notification Details...";
      CharSequence contentText = "Browse Android Official Site by clicking me";
      Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));
      PendingIntent intent =    PendingIntent.getActivity(AllClasses.this, 0,   notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

    notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

}

私のコードのエラーは、Calendar インスタンスを Notification コンストラクターに渡そうとしています。アラームではなく、ステータス バーの通知を使用するのに十分満足しています。このカレンダー オブジェクトを通知に渡す方法はありますか?

ありがとう!

4

1 に答える 1

0

変化する:

final Notification notifyDetails = new Notification(R.drawable.android_logo,
"New Alert, Click Me!",calendar);

これで;

final Notification notifyDetails = new Notification(R.drawable.android_logo,
"New Alert, Click Me!",calendar.getTimeInMillis());

定期的に実行したい場合は、Intent を ServiceIntent に送信するアラームを使用し、この中で通知を起動する必要があります。

于 2012-11-07T15:33:41.390 に答える