1
У меня проблема. Когда я нажимаю на уведомление, будет отменено, но он не откроет действие. Это код:Android Уведомления о новинке
GcmIntentService.java
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
con)
.setAutoCancel(true)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.FLAG_AUTO_CANCEL)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getText(R.string.app_name))
.setContentText(msg);
Intent resultIntent = new Intent(con, Notification.class);
resultIntent.putExtra("message", msg);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(con);
stackBuilder.addParentStack(Home.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT
| Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
EDIT:
Я решил с этим кодом:
Intent intent = new Intent(this, Home.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setContentTitle(getText(R.string.app_name))
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
А теперь мое уведомление работа!
Не функция. – Ruben
@ ruben Вы попробовали проект API Demos? –
Как? Создать новый проект проекта, связанный с библиотекой? – Ruben