2012-01-12 11 views
5

मैं एक प्रोग्राम बना रहा हूं और मैं चाहता हूं कि ऐप अधिसूचना करे। जब अधिसूचना बंद हो जाती है तो केवल टिकर टेक्स्ट प्रदर्शित होता है। इसके साथ कोई ध्वनि या कंपन या प्रकाश नहीं है।अधिसूचना ध्वनि या कंपन नहीं बना रही है?

यहाँ मेरी कोड का एक उदाहरण है:

int icon = R.drawable.icon; 
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 

Context context = getApplicationContext();  

CharSequence contentTitle = "My notification"; 
CharSequence contentText = "Countdown Complete!"; 

Intent intent = new Intent(); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
Notification notification = new Notification(icon, myCountDown.getName() + " is completed!", System.currentTimeMillis()); 

long[] vibrate = {0,100,200,300}; 
notification.vibrate = vibrate; 
notification.defaults |= Notification.DEFAULT_LIGHTS; 
notification.defaults |= Notification.DEFAULT_SOUND; 
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); 
notificationManager.notify(myCountDown.getId(), notification); 

उत्तर

1

आप उपकरण म्यूट नहीं है यह सुनिश्चित किया है और वास्तव में (मूक भी नहीं) एक सूचना ध्वनि उपयोगकर्ता द्वारा उठाया गया है?

एक और बात होगी कोशिश करने के लिए:

[Note obj].sound = value 
[Note obj].LEDARGB = value 
[Note obj].vibrate = value 
+0

हाँ ध्वनि चालू है और अधिसूचना बंद होने पर मैंने ध्वनि डिंग उठाई। मैं कोड आज़माउंगा और देख सकता हूं कि यह काम करता है या नहीं। – Tj5

+0

मैंने कोशिश की और मुझे एहसास हुआ कि यह कंपन के लिए कम से कम क्या कर रहा है और मेरे कोड को अधिसूचना प्रबंधक को रोशनी और ध्वनि के लिए डिफ़ॉल्ट का उपयोग करने के लिए सूचित करना चाहिए ... तो यह अभी भी काम नहीं करता है – Tj5

3

एलईडी काम करने के लिए, आपको क्या करना है यह बताने के लिए की जरूरत है।

notification.ledOnMS = 1000; //Be on for a second 
    notification.ledOffMS = 1000; //Be off for a second 
    notification.ledARGB = Color.GREEN; //What colour should the LED be? 

कंपन काम करने के लिए, आपको अनुमति आपके प्रकट

<uses-permission android:name="android.permission.VIBRATE"/> 
8

को जोड़ने के लिए नोटिफिकेशन रोशनी करने के लिए जोड़ा की जरूरत है आप जोड़ने के लिए इस (.flags, .defaults नहीं नोटिस) की जरूरत है:

notification.flags |= Notification.FLAG_SHOW_LIGHTS; 
notification.ledARGB=0xffffffff; //color, in this case, white 
notification.ledOnMS=1000; //light on in milliseconds 
notification.ledOffMS=4000; //light off in milliseconds 

डिफ़ॉल्ट ध्वनि के लिए:

notification.defaults |= Notification.DEFAULT_SOUND; 

डिफ़ॉल्ट कंपन पैटर्न के लिए:

notification.defaults |= Notification.DEFAULT_VIBRATE; 

कंपन के लिए, के रूप में डीन थॉमस उल्लेख किया है, तो आपको एक अनुमति <uses-permission android:name="android.permission.VIBRATE"/>

0

मुझे लगता है की आवश्यकता होगी वहाँ NotificationCompat.Builder में एक setDefaults विधि है, और यह सूचना प्राथमिकताओं को एडजस्ट करने के लिए प्रदान करता है ।

NotificationManager notificationManager = (NotificationManager) 
      this.getSystemService(Context.NOTIFICATION_SERVICE); 

NotificationCompat.Builder builder = 
      new NotificationCompat.Builder(this); 

builder.setSmallIcon(R.drawable.taiwanpic) 
      .setWhen(System.currentTimeMillis()) 
      .setContentTitle("AAAAA") 
      .setContentText("BBBBB") 
      .setSubText("CCCCC") 
      .setContentInfo("DDDDD") 
      .setTicker("EEEEE") 
      .setDefaults(Notification.DEFAULT_ALL); 
int pid = android.os.Process.myPid(); 

notificationManager.notify(pid, builder.build()); 

आप सभी मूलभूत मूल्यों का उपयोग नहीं करते हैं, तो आप भी कोशिश कर सकते हैं DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS के रूप में आप चाहते हैं: यहाँ एक उदाहरण है।

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