मैं एक अधिसूचना का निर्माण करने के लिए Notification.Builder का उपयोग करता हूं । अब मैं डिफ़ॉल्ट ध्वनि सूचना का उपयोग करना चाहता हूं:
builder.setSound(Uri sound)
लेकिन उरी को डिफ़ॉल्ट अधिसूचना कहां है?
मैं एक अधिसूचना का निर्माण करने के लिए Notification.Builder का उपयोग करता हूं । अब मैं डिफ़ॉल्ट ध्वनि सूचना का उपयोग करना चाहता हूं:
builder.setSound(Uri sound)
लेकिन उरी को डिफ़ॉल्ट अधिसूचना कहां है?
जवाबों:
डिफॉल्ट नोटिफिकेशन उरी प्राप्त करने के लिए RingtoneManager का उपयोग करके देखें :
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);
Settings.System.DEFAULT_NOTIFICATION_URI
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
साथ ही काम करता है
Default Notification Sound
हैं:mBuilder.setDefaults(Notification.DEFAULT_SOUND);
या RingtoneManager वर्ग का उपयोग कर :
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
ये सभी तरीके काम करते हैं
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
आप इसका उपयोग कर सकते हैं:
Uri uri = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).
getString("pref_tone", "content://settings/system/notification_sound"));
mBuilder.setSound(uri);
application
चैनल साउंड न हो डिफॉल्ट सिस्टम साउंड को NotificationChannel channel = new NotificationChannel(ApplicationClass.getInstance().HighNotificationChannelID, getString(R.string.incoming_sms), NotificationManager.IMPORTANCE_HIGH); channel.getSound();
रिटर्न के साथ आज़माएं default system sound
कृपया मदद करें
सिस्टम डिफॉल्ट नोटिफिकेशन के लिए
उड़ी उरई = रिंगटोनमनेगर.गेटडिफॉल्टयूरी (रिंगटोनओनमैनगर .YPE_NOTIFICATION);
कस्टम अधिसूचना के लिए
Uri customSoundUri = Uri.parse ("android.resource: //" + getPackageName () + "/" + R.raw.twirl);
अधिसूचना ध्वनि का स्रोत (मैंने "घुमाव" का नाम दिया और res-> कच्चे फ़ोल्डर में रखा)
https://notificationsounds.com/message-tones/twirl-470
अधिसूचना बिल्डर:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notificaion_icon)
.setContentTitle("Title here")
.setContentText("Body here")
.setSound(defaultSoundUri)
.setAutoCancel(true);
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(id, mBuilder.build());
अगर किसी को अभी भी ज़रूरत है, तो यह ध्वनि और कंपन के साथ बिल्कुल ठीक काम करता है।
Context context = getApplicationContext();
long[] vibrate = new long[] { 1000, 1000, 1000, 1000, 1000 };
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Resources res = context.getResources();
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.notif)
.setTicker("lastWarning")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setVibrate(vibrate)
//.setContentTitle(res.getString(R.string.notifytitle))
.setContentTitle("Notification")
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
//.setContentText(res.getString(R.string.notifytext))
.setContentText("Notification text");
// Notification notification = builder.getNotification(); // until API 16
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFY_ID, notification);
यदि आप उदाहरण के लिए अक्षम करना चाहते हैं तो कंपन परिवर्तन नए लंबे समय तक कंपन [{0,0,0,0,0}; लगभग इसी तरह की बात आप ध्वनि के साथ कर सकते हैं या यदि अन्य कथन का उपयोग कर सकते हैं।