2016-08-10 14 views
0

Benachrichtigung wird geöffnet, sobald sie gepostet wird und keine Aktion des Benutzers erforderlich ist.Benachrichtigung wird automatisch ohne Klicken geöffnet

Hier ist mein Code:

private void sendNotification(String message,String title,String id,String book) { 
    smLocalStore=new SMLocalStore(this); 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    Log.i("id:",id); 
    intent.putExtra("id",id); 
    intent.putExtra("val","1"); 
    intent.putExtra("book",book); 
    int requestCode = 0; 
    //notification sending 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); 
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) 
       .setSound(sound) 
       .setSmallIcon(R.mipmap.ic_lau) 
       .setLargeIcon(largeIcon) 
       .setContentTitle(title) 
       .setFullScreenIntent(pendingIntent,true) 
       .setContentText(message) 
       .setStyle(new NotificationCompat.BigTextStyle() 
         .bigText(message)) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent); 
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(x, noBuilder.build()); //0 = ID of notification 
} 

Antwort

2

Entfernen aus dem Code folgende Zeile:

.setFullScreenIntent(pendingIntent,true) 

Android Developer Documentation sagt:

setFullScreenIntent(PendingIntent intent, boolean highPriority)

Eine Absicht zu starten statt Post Die Benachrichtigung wird in der Statusleiste angezeigt.

+0

thankyouu ....... es half :) – felix

+0

so bitte überprüfen und upvote meine Antwort –

+0

Für mehrere Benachrichtigungen, wie ein einzelnes Benachrichtigungssymbol in der Statusleiste angezeigt – felix

Verwandte Themen