2015-11-03 15 views
6

Come ottenere una notifica di testata. Con il codice sottostante posso vedere solo tre punti sulla barra di stato e una notifica nella barra di notifica.Come mostrare le notifiche Heads up android

Intent intent = new Intent(this, MainActivity.class); 

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,PendingIntent.FLAG_ONE_SHOT); 
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.bip); 
Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.bip) 
       .setContentTitle("Temp") 
       .setPriority(NotificationCompat.PRIORITY_HIGH) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

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

notificationManager.notify(0, notificationBuilder.build()); 
+3

Beh questo è uno sciocco. Devo accedere alle impostazioni selezionare la mia app e modificare le impostazioni di notifica dell'app. Dopo che le notifiche headsup erano visibili. Ma come Facebook e altre app fanno fuori questa confusione di impostazioni. – user1837779

+0

Si prega di dare un'occhiata alla loro documentazione: http://developer.android.com/guide/topics/ui/notifiers/notifications.html – DNC

risposta

8

Questo codice funziona per me:

NotificationCompat.Builder mBuilder = 
        new NotificationCompat.Builder(context) 
          .setSmallIcon(R.drawable.ic_media_play) 
          .setContentTitle("My notification") 
          .setContentText("Hello World!") 
          .setDefaults(Notification.DEFAULT_ALL) 
          .setPriority(Notification.PRIORITY_HIGH); 
Problemi correlati