उरी डिफॉल्ट साउंड नोटिफिकेशन?


123

मैं एक अधिसूचना का निर्माण करने के लिए Notification.Builder का उपयोग करता हूं । अब मैं डिफ़ॉल्ट ध्वनि सूचना का उपयोग करना चाहता हूं:

builder.setSound(Uri sound)

लेकिन उरी को डिफ़ॉल्ट अधिसूचना कहां है?

जवाबों:


267

डिफॉल्ट नोटिफिकेशन उरी प्राप्त करने के लिए RingtoneManager का उपयोग करके देखें :

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

builder.setSound(uri);

50
धन्यवाद। लेकिन मैंने देखा है कि मैं setDefaults (Notification.DEFAULT_SOUND) का भी उपयोग कर सकता
हूं

8
आप इसे भी पास कर सकते हैंSettings.System.DEFAULT_NOTIFICATION_URI
प्रतीक बुटानी


29

उपयोग करने के लिए दो विकल्प Default Notification Soundहैं:

mBuilder.setDefaults(Notification.DEFAULT_SOUND);

या RingtoneManager वर्ग का उपयोग कर :

mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));


3

आप इसका उपयोग कर सकते हैं:

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कृपया मदद करें
सागर 12

3

सिस्टम डिफॉल्ट नोटिफिकेशन के लिए

उड़ी उरई = रिंगटोनमनेगर.गेटडिफॉल्टयूरी (रिंगटोनओनमैनगर .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());

0

अगर किसी को अभी भी ज़रूरत है, तो यह ध्वनि और कंपन के साथ बिल्कुल ठीक काम करता है।

        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}; लगभग इसी तरह की बात आप ध्वनि के साथ कर सकते हैं या यदि अन्य कथन का उपयोग कर सकते हैं।

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.