6

Sto riscontrando problemi nel far funzionare le notifiche Big Text di Android come documentato qui: NotificationCompat.BigTextStyle. Ecco il codice che sto usando per visualizzare le notifiche. So che tutti i dati tornano correttamente perché posso visualizzarli sulla console e come testo e titolo del contenuto tradizionale. Sto facendo qualcosa di sbagliato? Devo definire bigTestStyle da qualche altra parte? Spero che qualcuno di voi abbia fatto questo prima e sappia cosa potrebbe mancare. Grazie.Notification Big Text Android GCM

As you can see the big text message text is not displaying

Il mio codice:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
    bigTextStyle.bigText(extras.getString("message")); 
    NotificationCompat.Builder bigTextNotification = new NotificationCompat.Builder(context) 
      .setContentTitle("My App") 
      .setContentIntent(pendingIntent) 
      .setContentText("Message:") 
      .setSound(soundUri) 
      .setTicker(extras.getString("message")) 
      .setWhen(System.currentTimeMillis()) 
      .setSmallIcon(R.drawable.splash) 
      .setAutoCancel(true) 
      .setVibrate(new long[] { 0, 100, 200, 300 }) 
      .setStyle(bigTextStyle); 
    final int notificationId = (int) (System.currentTimeMillis()/1000L); 
    NotificationManager thisone = (NotificationManager) getApplicationContext() 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    thisone.notify(notificationId, bigTextNotification.build()); 
+0

Ho un canvas micromax A74, versione Android 4.2.2.Utilizzo di 'NotificationCompat' ha funzionato bene per me.Tuttavia quando uso' Notification.Bulider', 'BigTextStyle' funziona bene ma il normale stile di notifica non funziona.Esso visualizza l'icona di notifica senza alcun testo al suo interno. –

risposta

4

Da NotificationCompat.BigTextStyle documentazione:

classe Helper per la generazione di notifiche di grande formato che comprendono un sacco di testo. Se la piattaforma non fornisce notifiche di grande formato, questo metodo non ha effetto. L'utente vedrà sempre la normale visualizzazione delle notifiche.

Forse la tua piattaforma non supporta le notifiche di grande formato.

EDIT:

D'altra parte, è possibile che il vostro problema è qui:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
bigTextStyle.bigText(extras.getString("message")); 

Non si utilizza il valore di ritorno di bigText.

cercare di cambiarlo a:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
bigTextStyle = bigTextStyle.bigText(extras.getString("message")); 

oppure a:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(extras.getString("message")); 

EDIT2:

layout di notifica Costom per le versioni più vecchie di Android:

protected void onMessage(Context context, Intent intent) { 
    // Extract the payload from the message 
    Bundle extras = intent.getExtras(); 
    if (extras != null) { 
     String message = (String) extras.get("message"); 
     String title = (String) extras.get("title");     

     // add a notification to status bar 
     NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent myIntent = new Intent(this,MyActivity.class); 
     Notification notification = new Notification(R.drawable.notification_image, title, System.currentTimeMillis()); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); 
     contentView.setImageViewResource(R.id.image, R.drawable.notification_image); 
     contentView.setTextViewText(R.id.title, title); 
     contentView.setTextViewText(R.id.text, message); 
     notification.contentView = contentView; 
     notification.contentIntent = PendingIntent.getActivity(this.getBaseContext(), 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT); 
     mManager.notify(0, notification); 
     PowerManager pm = (PowerManager) 
     context.getSystemService(Context.POWER_SERVICE); 
     WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); 
     wl.acquire(15000); 
    } 
} 
+0

Nessuno dei due ha funzionato. Non sono sicuro che bigTextStyle venga creato come parte di bigTextNotification – centree

+0

In tal caso è possibile che il tuo dispositivo o la versione Android non supportino le notifiche di grande formato. – Eran

+0

Sto usando un nuovissimo S3. – centree

Problemi correlati