2012-08-30 6 views
16

मैं निम्नलिखित कोड है जो मैं एक android ऐप के लिए उपयोग कर रहा हूँ है:एक स्थायी सूचना बनाएँ और स्थिति पट्टी में अधिसूचना को रोकने

package com.authorwjf.e_notifications; 

import android.app.Activity; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 

public class Main extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Bitmap bm = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.avatar), 
       getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), 
       getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height), 
       true); 
     Intent intent = new Intent(this, Main.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 01, intent, Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     Notification.Builder builder = new Notification.Builder(getApplicationContext()); 
     builder.setContentTitle("This is the title"); 
     builder.setContentText("This is the text"); 
     builder.setSubText("Some sub text"); 
     builder.setNumber(101); 
     builder.setContentIntent(pendingIntent); 
     builder.setTicker("Fancy Notification"); 
     builder.setSmallIcon(R.drawable.ic_launcher); 
     builder.setLargeIcon(bm); 
     builder.setAutoCancel(true); 
     builder.setPriority(0); 
     Notification notification = builder.build(); 
     NotificationManager notificationManger = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManger.notify(01, notification);   
    } 

} 

मूल रूप से लॉन्च होने पर ऐप्स को वह नोटिफिकेशन बनाता है, अब मैं कुछ प्रश्न हैं:

  • क्या यह संभव है जब ऐप लॉन्च किया गया हो, अधिसूचना को पुल डाउन अधिसूचना सूची में दिखाया गया है लेकिन स्टेटस बार में आइकन के बिना। अर्थात।

http://imagebin.org/226494

का उल्लेख नहीं प्रदर्शित किया जा सकता आइकन लाल रंग में परिक्रमा? आखिरकार मैं ऐसी सेवा बनाना चाहता हूं जो सिर्फ पुल डाउन अधिसूचना में बैठे।

  • पुलडाउन जारी रखने में अधिसूचना बनाने के लिए दूर है यानी। यदि नीले रंग में घूमने वाला आइकन (http://imagebin.org/226494) दबाया जाता है कि अधिसूचना अभी भी बनी हुई है?

मैं एंड्रॉइड देव के लिए नया हूं और अधिसूचनाओं के साथ मैं जो कुछ कर सकता हूं उसके साथ पकड़ने की कोशिश कर रहा हूं।

धन्यवाद

+0

छवि स्थिति पट्टी आइकन इस चाल को हटाने, उपयोग करने के लिए पोस्ट उपलब्ध नहीं हैं। आप imagebin.org – nandeesh

+0

हाय का उपयोग कर सकते हैं, इसके बारे में खेद है कि मैंने छविबिन – Dino

उत्तर

37
  • A1:

    builder.setSmallIcon(android.R.color.transparent); //Tested and worked in API 14 
    
  • A2:: इस लाइन presistant अधिसूचना बनाने के लिए, जोड़ें:

    builder.setOngoing(true) 
    
+0

पर सही देखूंगा! धन्यवाद – Dino

+0

@Dino आपका स्वागत है :-) – iTurki

+0

आप इसे पुराने एपीआई पर कैसे सेट करते हैं? API8 में कोई बिल्डर नहीं है। –

1

ongoing event flag पर एक नजर डालें। मेरा मानना ​​है कि यह सिस्टम की वाईफाई और यूएसबी कनेक्शन अधिसूचनाओं के समान चल रही अधिसूचनाएं बना सकता है।

+0

हाय के लिंक अपडेट किए हैं, धन्यवाद, मैं इस – Dino

संबंधित मुद्दे