How to set ringtone with RingtoneManager.ACTION_RINGTONE_PICKER?

后端 未结 4 1145
Happy的楠姐
Happy的楠姐 2020-11-30 01:53

I try to find solution here, but there are only solution for own/selected file, not for code when I call picker. I use following code when user press button:



        
相关标签:
4条回答
  • 2020-11-30 02:31

    The code is perfect and works for me. But you forgot to mention the permissions required..here it is. try this code..hope it helps

    <uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
      <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" ></uses-permission>
      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" ></uses-permission>
    
    0 讨论(0)
  • 2020-11-30 02:37
    Intent intent=new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtone);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, ringtone);
    startActivityForResult(intent , 1);
    

    "ringtone" is the uri in which I am saving the picked tone in onActivityResult().

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case 1:
                ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    
                // Toast.makeText(getBaseContext(),RingtoneManager.URI_COLUMN_INDEX,
                // Toast.LENGTH_SHORT).show();
                break;
    
            default:
                break;
            }
        }
    }
    

    Hope it helps you. Hit answered if it does.

    0 讨论(0)
  • 2020-11-30 02:40

    You must implement onActivityResult() to receive result from user's pick, then save it.

    if (resultCode == RESULT_OK) {
        Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (uri != null) {
        String ringTonePath = uri.toString();
    }
    

    Here an example: http://www.ceveni.com/2009/07/ringtone-picker-in-android-with-intent.html

    EDIT: update

    RingtoneManager.setActualDefaultRingtoneUri(
        myActivity,
        RingtoneManager.TYPE_RINGTONE,
        uri);
    

    You must call this :)

    0 讨论(0)
  • 2020-11-30 02:50

    This code will show default ringtone which the user sets earlier when ringtone picker is used.

    Use below code in the button for ringtone intent.

    public void pickRingtone(View view) {
            // TODO Auto-generated method.   stub
    
            Intent intent = new.       Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
                    RingtoneManager.TYPE_RINGTONE);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Ringtone");
    
        // for existing ringtone
            Uri urie =     RingtoneManager.getActualDefaultRingtoneUri(
                    getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, urie);
    
        startActivityForResult(intent, 5);
    }
    
    0 讨论(0)
提交回复
热议问题