2013-06-02 3 views
6

मैंने Notification.Builder और Notification कक्षाओं का उपयोग करने का प्रयास किया।मेरा ऐप चलने पर स्टेटस बार में मेरे ऐप का आइकन कैसे जोड़ें?

मैं इस कोड का उपयोग करने की कोशिश की:

Notification notification = new Notification.Builder(this).build(); 
notification.icon = R.drawable.ic_launcher; 
notification.notify(); 

लेकिन यह बेकार लगता है।

मैं केवल बैटरी आइकन, वाईफ़ाई आइकन और 3 जी आइकन के बगल में अपना ऐप आइकन जोड़ना चाहता हूं .. ऐसा करने का कोई तरीका? तुम्हारी सहायता सराहनीय है।

+0

की संभावित डुप्लिकेट का प्रयास करें [कैसे स्थिति पट्टी में एक आइकन जब आवेदन चल रहा है, पृष्ठभूमि में सहित दिखाने के लिए?] (http://stackoverflow.com/questions/3973208/how-to- शो-ए-आइकन-इन-द-स्टेटस-बार-कब-एप्लिकेशन-चल रहा है-इन-इन) –

उत्तर

5

आपको अपनी सूचना का वर्णन करने के बाद विधि निर्माण() को कॉल करना होगा। उदाहरण के लिए Android reference देखें।

मूल रूप से, आप निम्नलिखित के लिए अपने कोड बदलने के लिए:

Context context = getApplicationContext(); 
NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
.setSmallIcon(R.drawable.ic_launcher);  

Intent intent = new Intent(context, MainActivity.class); 
PendingIntent pIntent = PendingIntent.getActivity(context, mID , intent, 0); 
builder.setContentIntent(pIntent); 
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

Notification notif = builder.build(); 
mNotificationManager.notify(mID, notif); 

नोट: इस कोड को केवल सूचना पट्टी में अपने आइकन दिखाने के लिए अनुमति देगा। यदि आप इसे वहां जारी रखना चाहते हैं, तो आपको FLAG_ONGOING_EVENT

+0

यह काम नहीं किया .. – ARMAGEDDON

+0

पिछला कोड आइकन दिखाने के लिए उचित ऑर्डरिंग करना था। मैंने आपकी टिप्पणी को दर्शाने के लिए उत्तर संपादित किया। – verybadalloc

+0

वह उस आइकन को दाईं ओर नहीं जोड़ता है जहां बैटरी और सिग्नल आइकन हैं। –

0

का उपयोग करना होगा आप स्टेटस बार अधिसूचना के लिए अपना ऐप आइकन जोड़ सकते हैं। यह एक

Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher).build(); 
संबंधित मुद्दे