2015-07-13 40 views
5

Ana tema kullandıktan sonra bile bildirim tıkladıktan sonra Android lolipop içinde Bildirimi kaldırılamıyorbile benim app AUTOCANCEL

private void sendNotification(Context context, String message) { 

SharedPreferences mPrefs = getSharedPreferences("MYAPP", Context.MODE_PRIVATE); 

int uniqueNumber = this.getSharedPreferences("MYAPP", Context.MODE_PRIVATE).getInt("uniqueNumber", 0); 
    Log.d("GCM: GN", "Message: " + message); 

    uniqueNumber = ++uniqueNumber; 
    int icon = R.drawable.ic_launcher; 

    long when = System.currentTimeMillis(); 

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

    Notification notification = new Notification(icon, message, when); 

    String title = context.getString(R.string.app_name); 

    Intent intent = new Intent(GCMIntentService.this,OpenActivity.class); 
    intent.putExtra(OpenActivity.EXTRA_KEY, "navigate"); 
    intent.putExtra(OpenActivity.GET_NOTIFY_ID_EXTRA, uniqueNumber); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 
    notification.setLatestEventInfo(context, title, message, pendingIntent); 
    notification.flags |= Notification.DEFAULT_LIGHTS|Notification.FLAG_AUTO_CANCEL ; 

    notification.defaults |= Notification.DEFAULT_SOUND; 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notificationManager.notify(uniqueNumber, notification); 

    SharedPreferences.Editor prefsEditor = mPrefs.edit(); 
    prefsEditor.putInt("uniqueNumber", uniqueNumber); 
    prefsEditor.commit(); 

} 
Google Bulut Mesajlaşma kullanarak mağazada Yeni teklifler PushNotification kullanarak kullanıcı için bildirim göndermektir

Çocuklar, bu kod parçası sadece Lollipop'ta çalışmıyor.

Herhangi bir yardım Takdir Edildi ...

+0

Destek Kitaplığı'nın [NotificationCompat.Builder] (http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html) veya hatta [Notification] 'ı kullanmamanızın bir nedeni var mı? .Builder] (http://developer.android.com/reference/android/app/Notification.Builder.html)? Kullandığınız kod 4 yıl kullanımdan kaldırıldı. – ianhanniballake

+0

Belirli bir nedeni yok. Daha önce Notification.Builder kullandım ama aynı sorunu aldım .. – saikiran

+0

Benim App NotificationCompat.Builder ile aynı sorun. – saikiran

cevap

0

Bunu deneyin. Projem için uygulamış olduğum gibi benim için iyi çalışıyor.

Sorun iyi değilse, lütfen aşağıdaki kodu kullanarak amaçlarınızı temizleyin.

Intent notificationIntent; 
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); 
+0

Katkınız için teşekkürler, ama işe yaramıyor ... – saikiran

+0

hey, sizin için niyet bayrakları ve bu iyi çalışıyor. –

+0

Hey, bu bayrakları kullandıktan sonra bile bu sorun çözülmedi ...... – saikiran

0

Lütfen bunu ekleyin ve kodunuza deneyin.

NOTIFICATION_COUNT = 10;

private void generateNotification(final String message, final String title, final String userType, final String userId) { 

     Log.e("message:", message); 
     int icon = R.drawable.ic_launcher; 
     long when = System.currentTimeMillis(); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent notificationIntent; 

     notificationIntent = new Intent(context, GroupMessagesActivity.class); 

     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); 
     PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

     Notification notification = new Notification(icon, message, when); 
     notification.setLatestEventInfo(context, title, message, intent); 
     notification.flags |= Notification.FLAG_SHOW_LIGHTS; 
     notification.flags |= Notification.DEFAULT_LIGHTS; 
     notification.flags = Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL; 

     Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
     long[] pattern = { 0, 100, 1500 }; 
     v.vibrate(pattern, -1); 
     notificationManager.notify(NOTIFICATION_COUNT, notification); 
     NOTIFICATION_COUNT = 1 + NOTIFICATION_COUNT; 
    } 
+0

Sadece küresel olarak NOTOFICATION_COUNT = 10 tanımlayın. –

+0

Ayrıca bu çalışma değil – tiru

+0

bu kod da çalışmıyor .. – saikiran

0
notification.flags |= Notification.FLAG_AUTO_CANCEL; 

bu deneyin.

+0

Ben de bu bildirim bayraklarını kullandık .. Bekleyen niyetle sorun yaşıyorum ... – saikiran

+0

bu benim nexus içinde iyi çalışıyor. –

0

Kendi etkinlik temanızı değiştirmeyi deneyin. Kendi özel temanızı kullanıyorsanız, bunu android tarafından sağlanan biriyle değiştirmeyi deneyin.

İlgili konular