私のアプリケーションでは、このコードを使用して通知を使用します。
private void addDefaultNotification(){
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence text = "Notification Text";
CharSequence contentTitle = "Notification Title";
CharSequence contentText = "Sample notification text.";
long when = System.currentTimeMillis();
Intent intent = new Intent(this, NotificationViewer.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon,text,when);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.ledARGB = Color.RED;
notification.ledOffMS = 300;
notification.ledOnMS = 300;
notification.defaults |= Notification.DEFAULT_LIGHTS;
//notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
notificationManager.notify(com.example.NotifivcationSample.Constants.NOTIFICATION_ID, notification);
}
今、私は通知を受け取っています。その関数を呼び出すことによって。しかし、私が欲しいのは、アプリケーションがその時点でデバイス上で実行されていない場合でもユーザーに通知し、通知を希望の時間に通知する必要があることです。
出来ますか ?はいの場合は、そのために私を助けてください。ありがとう。
編集:
public class AlarmNotificationReceiver extends BroadcastReceiver{
//private Intent intent;
private NotificationManager notificationManager;
private Notification notification;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long value1 = intent.getLongExtra("param1", 0);
String value2 = intent.getStringExtra("param2");
addTwoMonthNotification();
}
}
私はそのようにしましたが、そのレシーバークラスで通知を作成できませんでした。なんで ?そして私は何をしなければなりませんか?