2015-11-26 3 views
0

Я пытаюсь передать значение моего push-уведомления в свою деятельность. Но он всегда возвращает null.Как я могу передать дополнительную строку из Уведомления в действие

Вот как я пытаюсь передать дополнительную строку:

Intent notificationIntent = new Intent(context, Register.class); 
notificationIntent.putExtra("NotificationMessage", new_key.toString()); 
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 

PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 
notification.setLatestEventInfo(context, title, message, intent); 
notification.flags |= Notification.FLAG_AUTO_CANCEL; 

// Play default notification sound 
notification.defaults |= Notification.DEFAULT_SOUND; 
notification.defaults |= Notification.DEFAULT_VIBRATE; 
notificationManager.notify(0, notification);  

Вот моя деятельность, где я пытаюсь получить эту дополнительную строку.

Intent intent = getIntent(); 
String msg = intent.getStringExtra("NotificationMessage"); 
Toast.makeText(this, "Hello"+msg, Toast.LENGTH_LONG).show(); 

Этот тост всегда показывают мне "Привет нуль". Кто-нибудь может помочь?

Заранее спасибо.

ответ

0

Добавить PendingIntent в ваше уведомление по телефону .setContentIntent(). Он будет инициировать намерение при нажатии на уведомление.

Notification notification = new NotificationCompat.Builder(context) 
     ... 
     .setContentIntent(intent) 
     ... 
     .build(); 
+0

это не работает для меня ... –

+0

Попробуйте с флагом 'FLAG_ACTIVITY_NEW_TASK' –

+0

Нет же результат NULL –

Смежные вопросы