2014-11-10 3 views
0

Прежде всего, очень жаль, если это дубликат, хотя я думаю, что это не так, я много искал, но ничего не нашел. Я хочу удалить уведомление по щелчку отмены - который я нашел где-то, чтобы вызвать метод .cancel(), но где я должен сделать этот вызов. Другой, когда я нажимаю на принятие или отмену значений намерений, становится таким же, что и «Уведомления» в логарифме. Пожалуйста, дайте мне знать, что я делаю неправильно. Заранее спасибо.действия уведомлений в android

Мой уведомление создатель -

Intent intent1 = new Intent(context, code.omnitrix.slidingmenu.MainActivity.class); 
     if(message.contains("Blood Request")){ 
      intent1.putExtra("fragment", "Notifications"); 
      Log.d("Intent sent", intent1.getExtras().getString("fragment")); 
     }else if(message.contains("Thank")){ 
      intent1.putExtra("fragment", "myDonations"); 
     } 

     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
       intent1, PendingIntent.FLAG_CANCEL_CURRENT); 


     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(context); 
     mBuilder.setSmallIcon(R.drawable.ic_launcher);   
     mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); 
     mBuilder.setContentText(message); 
     //.setContentTitle("Thank you") 
     if(message.contains("Blood Request")){ 
      mBuilder.setContentTitle("Blood Request"); 
      Intent intent2 = new Intent(context, code.omnitrix.slidingmenu.MainActivity.class); 
      intent2.putExtra("fragment", "accept"); 
      PendingIntent acceptIntent = PendingIntent.getActivity(context, 0, intent2, 0); 
      Intent intent3 = new Intent(context, GcmBroadcastReceiver.class); 
      intent3.putExtra("fragment", "reject-1"); 
      PendingIntent rejectIntent = PendingIntent.getActivity(context, 0, intent3, 0); 
      mBuilder.addAction(R.drawable.tick_32, "Accept", acceptIntent); 
      mBuilder.addAction(R.drawable.cross_32, "Reject", rejectIntent); 
     } 


     mBuilder.setContentIntent(contentIntent); 
     mBuilder.setAutoCancel(true); 
     mNotificationManager.notify(1, mBuilder.build()); 

В то время как другой файл, который намерен приемник это как -

Intent intent = getIntent(); 
      String fragmentToDisplay = intent.getStringExtra("fragment"); 
      Log.d("Vinit", "Intent Received"); 
      if(fragmentToDisplay!=null){ 
       Log.d("From Intent", fragmentToDisplay); 
       if(fragmentToDisplay.equalsIgnoreCase("updateDetails")){ 
        //show update details fragment 
        Fragment fragment = new UpdateDetails(); 
        FragmentManager fragmentManager = getFragmentManager(); 
        fragmentManager.beginTransaction() 
          .replace(R.id.frame_container, fragment).commit();  
       }else if(fragmentToDisplay.equalsIgnoreCase("Notifications")){ 
        Fragment fragment = new Notifications(); 
        FragmentManager fragmentManager = getFragmentManager(); 
        fragmentManager.beginTransaction() 
          .replace(R.id.frame_container, fragment).commit(); 
       }else if(fragmentToDisplay.equalsIgnoreCase("accept")){ 
        //just send the response to the server. 
        //put in sqlite database. 
        Log.d("Fragment inside", "accept"); 
       }else if(fragmentToDisplay.equalsIgnoreCase("reject")){ 
        //just remove the request from the notifications. 
        Log.d("Fragment inside", "reject"); 
       } 
      } 
+0

кому угодно ... – codeomnitrix

ответ

0

1), чтобы удалить уведомление об отмене нажмите: добавить этот код в ресивера

if(fragmentToDisplay.equalsIgnoreCase("reject")){ 
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    manager.cancel(notificationId); 
    Log.d("Fragment inside", "reject"); 
} 

PS: вы использовали « "как notificationId в вашем коде (mNotificationManager.notify(1, mBuilder.build());), лучший способ - отправить его с помощью putExtra() и извлечь его в свой приемник.

2) Извините, я не понял вторую часть вашего вопроса. можете ли вы объяснить больше?

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