2011-12-07 11 views
7

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

क्या एंड्रॉइड अधिसूचना केवल ऑडियो अलर्ट चलाने के लिए संभव है? मैंने इसके बजाय wav फ़ाइल चलाने के लिए MediaPlayer का उपयोग करने का प्रयास किया है, लेकिन यह अपनी स्वयं की वॉल्यूम सेटिंग्स का उपयोग करता है, न कि नियमित अधिसूचना वॉल्यूम, इसलिए यदि आपका मीडिया वॉल्यूम कम है तो अधिसूचना ध्वनि कम मात्रा में भी खेलती है जो मैं नहीं चाहता हूं। मैं ध्वनि को अन्य अधिसूचनाओं के समान मात्रा में खेलना चाहता हूं।

मैं इस का उपयोग कर रहा: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

और इस तरह ध्वनि की आपूर्ति:

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd); 
+0

हाँ, यह संभव है setSound करने के लिए केवल एक ऑडियो चेतावनी खेलते हैं। –

+1

धन्यवाद @ coder_For_Life22, क्या आप मुझे दिखाएंगे कि कैसे? – Daniel

उत्तर

5

में http://developer.android.com/guide/topics/ui/notifiers/notifications.html में अनुभाग इस टिप्पणी है 'एक ध्वनि जोड़ना':

Note: If the defaults field includes DEFAULT_SOUND, then the default sound overrides any sound defined by the sound field.

तो, यदि आप केवल ध्वनि को कस्टमाइज़ करना चाहते हैं, तो आप इसका उपयोग कर सकते हैं -

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd); 
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE; 
3

मेरे प्रयोग के अनुसार, आप वास्तव में अधिसूचना क्षेत्र में दिखाई देने के बिना एक अधिसूचना भेज सकते हैं लेकिन अभी भी ध्वनि बजाई गई है।

आपको केवल एक अधिसूचना निर्माता बनाने और ध्वनि सेट करने की आवश्यकता है, लेकिन लंबित इरादे, आइकन, सामग्री शीर्षक और सामग्री टेक्स्ट को छोड़ना है।

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setSound(your_sound_uri); 
notificationManager.notify(1234, builder.build()); 
+1

ये उत्तर विशेष रूप से सहायक हैं क्योंकि दस्तावेज़ इस बारे में गलत हैं। http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CreateNotification कहता है, "एक अधिसूचना ऑब्जेक्ट * में निम्नलिखित होना चाहिए: setSmallIcon() द्वारा सेट किया गया एक छोटा आइकन, एक शीर्षक, सेट setContentTitle() द्वारा; विस्तार टेक्स्ट, setContentText() द्वारा सेट किया गया " – Jerry101

+2

आइकन आवश्यक है। यह एक त्रुटि का कारण बनता है: java.lang.IleglegalArgumentException: अमान्य अधिसूचना (कोई वैध छोटा आइकन नहीं) –

0
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

Notification mNotification = new Notification.Builder(this) 

      .setContentTitle("New Post!") 
      .setContentText("Here's an awesome update for you!") 
      .setSmallIcon(R.drawable.ic_lancher) 
      .setContentIntent(pIntent) 
      .setSound(soundUri) 
      .build(); 
0
NotificationCompat.Builder builder= new NotificationCompat.Builder(this); 

तीन तरीके

builder.setDefaults(Notification.DEFAULT_SOUND); 
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); 
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); 
संबंधित मुद्दे