0

我有以下代码,并且在更改 Android 中的铃声时遇到问题。我把这段代码变红了应该可以解决我的问题(保存更改后的铃声):

 RingtoneManager .setActualDefaultRingtoneUri( CustomizeActivity.this,
 RingtoneManager.TYPE_RINGTONE, Uri .parse("Media file uri"));

但我不知道我应该把它放在哪里。请帮忙。国王问候,

button4.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                String uri=null;

                ****//First URI
                RingtoneManager .setActualDefaultRingtoneUri( CustomizeActivity.this, RingtoneManager.TYPE_RINGTONE, Uri .parse("Media file uri"));****


                Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
                if (uri !=null) {
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(uri));

                }else{
                    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri)null);
                }
                startActivityForResult(intent, 1);


            }
        });
    }
4

1 回答 1

1

将此代码放在onActivityResult.like上

@Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        super.onActivityResult(requestCode, resultCode, data);  
        if (resultCode != RESULT_OK) {  
            return;  
        } else {  
            Uri uri = data  
                    .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);  
            if (uri != null) {  
                switch (requestCode) {  
                case 1:  
                    RingtoneManager.setActualDefaultRingtoneUri(this,  
                            RingtoneManager.TYPE_RINGTONE, uri);  
                    break;  
                default:  
                    break;  
                }  
            }  

        }  
    }
于 2012-04-04T20:04:23.923 回答