2015-11-03 12 views
6

Nasıl bir bildirim başlatmak için. Aşağıdaki kod ile sadece durum çubuğunda üç nokta ve bildirim çubuğunda bir bildirim görebilirsiniz.Nasıl Heads up bildirimleri göstermek için 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

Eh bu saçma biridir. Ayarlarımın uygulamamı seçmesi ve uygulama bildirim ayarlarını değiştirmesi gerekiyor. Bu başlık bildirimleri göründükten sonra. Ancak facebook ve diğer uygulamalar bu ayarlarla nasıl başa çıkıyor. – user1837779

+0

Lütfen belgelerine bir göz atın: http://developer.android.com/guide/topics/ui/notifiers/notifications.html – DNC

cevap

8

Bu kod benim için çalışıyor:

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); 
İlgili konular