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); 

А теперь мое уведомление работа!

ответ

0

Попробуйте это: (необходимо указать запуск деятельности намерение, которое вы должны положить в ожидании намерения)

, пожалуйста, прочитайте следующую инструкцию для создания рабочих уведомлений с нуля: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

// Intent that will launch activity 
    Intent notifyIntent = new Intent(context, MainFragmentFaceActivity.class); 

    // Creates the PendingIntent 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, notifyIntent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 

    // Puts the PendingIntent into the notification builder 
    notificationBuilder.setContentIntent(pendingIntent); 

    notifyManager.notify(R.id.notification_move, notificationBuilder.build()); 
+0

Не функция. – Ruben

+0

@ ruben Вы попробовали проект API Demos? –

+0

Как? Создать новый проект проекта, связанный с библиотекой? – Ruben

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