0
私はそれをタップすると、それは単に閉じると、アプリが表示に戻って来ていないという通知があります。Context not NotificationReceiver(BroadcastReceiver)に渡さない
これは私のMainActivityである -
テントの意図=新しいテント(getApplicationContext()、NotificationReceiver.class)。intent.putExtra( "Message"、notificationText);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
その後NotificationReceiverはこのようになります -
public class NotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
String notificationText = intent.getStringExtra("Message");
//if we want ring on notification then uncomment below line
// Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.rr)
.setContentTitle("Check your reminders!")
.setContentText(notificationText)
.setAutoCancel(true);
notificationManager.notify(100, builder.build());
}
}
私のマニフェストでは、私はこれを持っています。
私は何が欠けていますか?
ありがとうございます!
素晴らしいです。ありがとうございました。 (できるだけ早く受け入れます) – AndyCr15