2013-02-27 29 views
8

मैं एक कस्टम अधिसूचना बनाना चाहता हूं। तो मैं रोशनी और स्वर बदलना चाहता हूँ। मैं इसके लिए NotificationCompat.Builder का उपयोग करता हूं।अधिसूचना सेटलाइट्स() डिफ़ॉल्ट मान?

अब मैं लाइट्स को setLights() के माध्यम से बदलना चाहता हूं; ठीक काम करता है। लेकिन मैं onMS और offMS का डिफ़ॉल्ट मान सेट करना चाहता हूं। मुझे इसके बारे में कुछ नहीं मिला है।

क्या कोई मुझे डिफ़ॉल्ट मान खोजने में मदद कर सकता है? यहाँ उस के लिए प्रलेखन है: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLights(int, int, int)

उत्तर

1

आप के साथ ऐसा करने में सक्षम होना चाहिए:

Notifictaion notf = new Notification.Builder(this).setXXX(...).....build(); 
notf.ledARGB = <your color>; 
notf.ledOnMS = <your value>; //or skip this line to use default 
notf.ledOffMS = <your value>; //or skip this line to use default 

मूल रूप से, अधिसूचना बिल्डर पर setLights प्रयोग नहीं करते। इसके बजाय, पहले अधिसूचना बनाएं - फिर आपके पास रोशनी के लिए अलग-अलग फ़ील्ड तक पहुंच है।

अद्यतन: यह है वास्तविक कॉपी/मेरी नमूना परियोजना है, जो संकलित करता है तथा एंड्रॉयड 2.1 पर ठीक काम करता है और एलईडी के लिए नीले रंग का उपयोग करता है से पेस्ट:

Notification notf = new NotificationCompat.Builder(this) 
    .setAutoCancel(true) 
    .setTicker("This is the sample notification") 
    .setSmallIcon(R.drawable.my_icon) 
    .build(); 
notf.ledARGB = 0xff0000ff; 
NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(1, notf); 
+0

क्षमा करें, लेकिन यह उलझन में है। यू अधिसूचना नोट = = बिल्डर का उपयोग करें। वह नहीं चलता है। इसके अलावा मैं बिल्ड() को कॉल नहीं कर सकता। (मैं सबसे छोटा एसडीके 8 के रूप में उपयोग करता हूं)। तो मुझे builder.getNotification(); को कॉल करना होगा। लेकिन यह भी नहीं चल रहा है ... – StefMa

+0

@StefanM। मैंने अपने नमूना प्रोजेक्ट से वास्तविक कोड के साथ अपना जवाब अपडेट किया। 'अधिसूचना कॉम्पेट.बिल्डर .बिल्ड 'एपीआई स्तर 3 से उपलब्ध है। –

+0

केवल अधिक उलझन में ... बिल्ड() उपलब्ध नहीं है ग्रहण! और setIcon भी ... – StefMa

1

@Aleks जी मदद नहीं है कि । मेरे पास compat libaray से नवीनतम अपडेट है। लेकिन ग्रहण कहते हैं build() उपलब्ध नहीं है। मैं नहीं क्यों नहीं। दस्तावेज कहता है हाँ और आप ...

यह वह जगह है मेरे वर्तमान कोड:

NotificationCompat.Builder notify = new NotificationCompat.Builder(context); 
    notify.setLights(Color.parseColor(led), 5000, 5000); 
    notify.setAutoCancel(true); 
    notify.setSound(Uri.parse(tone)); 
    notify.setSmallIcon(R.drawable.ic_stat_kw); 
    notify.setContentTitle("Ttiel"); 
    notify.setContentText("Text"); 
    Intent showIntent = new Intent(context, Activity_Login.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, showIntent, 0); 
    notify.setContentIntent(contentIntent); 

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0, notify.getNotification()); 

रन पूरी तरह से। लेकिन नहीं डिफ़ॉल्ट onMS और offMSsetLights() :(

+0

बिल्ड() को API 16 में getNotification() के पर्याय के रूप में जोड़ा गया था, लेकिन वे वही काम करते हैं। – dsandler

6

में साथ जवाब के लिए Android source देखें:।

<!-- Default color for notification LED. --> 
<color name="config_defaultNotificationColor">#ffffffff</color> 
<!-- Default LED on time for notification LED in milliseconds. --> 
<integer name="config_defaultNotificationLedOn">500</integer> 
<!-- Default LED off time for notification LED in milliseconds. --> 
<integer name="config_defaultNotificationLedOff">2000</integer> 

हालांकि विभिन्न रोम इन अलग-अलग मान हो सकता है उदाहरण के लिए मेरा रिटर्न config_defaultNotificationLedOff के लिए 5000 तो तुम हो सकता है।

Resources resources = context.getResources(), 
      systemResources = Resources.getSystem(); 
notificationBuilder.setLights(
    ContextCompat.getColor(context, systemResources 
     .getIdentifier("config_defaultNotificationColor", "color", "android")), 
    resources.getInteger(systemResources 
     .getIdentifier("config_defaultNotificationLedOn", "integer", "android")), 
    resources.getInteger(systemResources 
     .getIdentifier("config_defaultNotificationLedOff", "integer", "android"))); 

diff के अनुसार, इन विशेषताओं exis की गारंटी है: उन्हें रनटाइम पर लाने के लिए चाहते हैं एंड्रॉइड 2.2+ (एपीआई स्तर 8+) पर टी।

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