2015-11-03 7 views
6

अधिसूचनाएं कैसे प्राप्त करें। कोड के नीचे मैं केवल स्टेटस बार पर तीन बिंदु देख सकता हूं और अधिसूचना बार में एक अधिसूचना देख सकता हूं।हेड अप अधिसूचनाएं एंड्रॉइड कैसे दिखाएं

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

खैर यह एक मूर्खतापूर्ण एक है। सेटिंग्स को पाने की आवश्यकता है मेरे ऐप का चयन करें और ऐप अधिसूचना सेटिंग्स बदलें। इसके बाद हेडस अधिसूचनाएं दिखाई दे रही थीं। लेकिन इस सेटिंग स्क्रूअप के साथ फेसबुक और अन्य ऐप्स कैसे करते हैं। – user1837779

+0

कृपया उनके दस्तावेज़ों पर एक नज़र डालें: http://developer.android.com/guide/topics/ui/notifiers/notifications.html – DNC

उत्तर

8

इस कोड मेरे लिए काम करता है:

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); 
संबंधित मुद्दे