how to access the ringtone per current with URI?

2

Hi, I'm doing a fake call app and I do not know how to use the default call tone that the phone has, I'm using uri to save the audio that the user of his music chooses, I just need the default tone

prefs=getSharedPreferences("MisPreferencias",this.MODE_PRIVATE);
        urimp3 = prefs.getString("urime",null);
        if(urimp3==null)
        {
            urim=Uri.parse("android.resource://"+getPackageName()+"/raw/mp3");
        }
        else{
            urim=Uri.parse(urimp3);
        }
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("urime",urim.toString());
        editor.apply();
        mPlayer = new MediaPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        try {
            mPlayer.setDataSource(getApplicationContext(), urim);
        } catch (IllegalArgumentException e) {
            Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (SecurityException e) {
            Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IllegalStateException e) {
            Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            mPlayer.prepare();
        } catch (IllegalStateException e) {
            Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
        }
        mPlayer.setLooping(true);
    
asked by Jose Luis Flamenco Chie 01.11.2018 в 04:38
source

1 answer

1

To get the Uri of the sound defined as default, you can do it this way:

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

But if you want to obtain the Uri to assign it to a notification it is not necessary to obtain the Uri, for this you have the property Notification.DEFAULT_SOUND :

notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);
    
answered by 01.11.2018 / 16:07
source