2016年3月15日 星期二

Get ringtone list from android settings

References:

http://stackoverflow.com/questions/2724871/how-to-bring-up-list-of-available-notification-sounds-on-android

Code snippet:

private static final int RINGTONE_REQUEST_CODE = 5;
public void requestProfileRingtone(){
 
    Intent ringtoneListIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,     RingtoneManager.TYPE_RINGTONE);
    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    startActivityForResult(ringtoneListIntent, RINGTONE_REQUEST_CODE);
}



@Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent){
        if (resultCode == Activity.RESULT_OK && requestCode == RINGTONE_REQUEST_CODE){
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            if (uri != null){
                Toast.makeText(this, "chosenRingtone: " + uri.toString(), toast.LENGTH_SHORT).show();
                Log.d(TAG, "chosenRingtone: " + uri.toString());
            } else{
                Toast.makeText(this, "chosenRingtone is null", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "chosenRingtone is null");
            }
        }
    }

沒有留言: