सभी सिस्टम साउंड प्रकार बजाना
यह आर्टिकल पिछले आर्टिकल के समान है - RingtoneManager के तीनों प्रकार (रिंगटोन, अलार्म, नोटिफिकेशन) को MediaPlayer से बजाने का तरीका दिखाता है।
कोड समान है (ID: 1005061538 देखें)
उपयोग के अनुसार सही टाइप चुनें
- TYPE_NOTIFICATION - ऐप नोटिफिकेशन, मैसेज, अपडेट (सबसे आम)
- TYPE_RINGTONE - इनकमिंग कॉल, वीडियो कॉल
- TYPE_ALARM - अलार्म ऐप, रिमाइंडर, क्रिटिकल अलर्ट
कस्टम साउंड के लिए
// res/raw/mysound.mp3 से
Uri customSound = Uri.parse("android.resource://" + getPackageName() + "/raw/mysound");
MediaPlayer mp = MediaPlayer.create(this, customSound);
mp.start();
नोटिफिकेशन चैनल में सेट करना (सही तरीका)
// Android 8.0+ NotificationChannel channel = new NotificationChannel(id, name, importance); channel.setSound(uri, audioAttributes); // MediaPlayer के बजाय यह उपयोग करें