2016-02-06 3 views
3

Я получаю уведомление в своем приложении через BroadcastReceiver, вопрос в том, как я могу разобрать данные для активности и сделать диалог с полученными данными?android - Как показать диалог при нажатии на уведомление

это мой код, но когда я нажимаю на уведомление, ничего не происходит:

NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); 

     Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 
     notificationIntent.setData(Uri.parse(link)); 
     PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK); 

     Notification myNotification = new NotificationCompat.Builder(ctx) 
       .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false).setLargeIcon(remote_picture) 
       .setContentTitle(onvan).setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) 
       .setContentText(msg).setContentIntent(pending).build(); 
     notificationManager.notify(1, myNotification); 

Я немного variablese как ссылку, сообщ, onvan, который содержит мои данные, и мне нужно отправить эти переменные и сделать диалог.

Как это сделать?

+0

проверить мой ответ. – Harshad

+0

http://stackoverflow.com/a/9751134/3514144 –

+0

использовать деятельность как диалог http://stackoverflow.com/a/1979631/1168654 –

ответ

0

Попробуйте это:

Intent notifyIntent = new Intent(context,YourActivityClassHere.class); 
notifyIntent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK); 
//UNIQUE_ID if you expect more than one notification to appear 
PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, UNIQUE_ID, 
      notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

просто сделать PendingIntent открыть один из ваших мероприятий и ваша активность полная прозрачной и просто открыть диалог.

EDIT: Если вы хотите открыть активность от события уведомления, нажмите:

Если предположить, что Notif ваших Уведомления объекта:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class); 
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0); 
notif.contentIntent = contentIntent; 

Для получения более детальной информации посетите здесь. Android - Prompt Dialog window when touch on Notification

1

Вы можете отправить данные с уведомлением другой Activity с использованием метода putExtra и поставить этот

PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT)); 

InPlace этого

PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);` 
Смежные вопросы