0
을 얻을 설정하려고 :는 기본 벨소리 내가 이것을 사용하기 위해 노력하고있어, SecurityException가
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
이 ... 기본 벨소리를 설정할 수 있습니다. 예외가 발생하고 유형은 SecurtyException
입니다.
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
은 ... 하나를 찾을 수 없습니다, 벨소리에 해당 menefest 파일에 설정할 수있는 권한이 있다면 볼 수 있습니다.
// make it a ring tone
void MakeRingtune(String name)
{
File newSoundFile = new File("/sdcard/", "myringtone.oog");
String strUri = "android.resource://"+getPackageName()+ "/" + "raw/"+name;
Uri mUri = Uri.parse(strUri);
ContentResolver mCr = getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
MessageBox("Ringtone Manager ","System Error cannot add ringtone ");
return;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(newSoundFile);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
MessageBox("Ringtone Manager ","Could not copy Ringtone, may be due to no sd card");
return;
}
//////////////////////////////////////////
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "my ringtone");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/oog");
values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length());
values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
Uri newUri = mCr.insert(uri, values);
try {
RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
} catch (Throwable t) {
// Log.d(TAG, "catch exception");
MessageBox("Ringtone Manager ","Could not set as your default ringtone ");
return;
}
///////////////////////////////////////
MessageBox("Ringtone Manager ","Sound Clip Added to your Ringtones");
} // end methed
사용자 벨소리에 액세스하고 변경하기위한 적절한 사용 권한을 설정 했습니까? –
<사용 권한 android : name = "android.permission.CHANGE_CONFIGURATION"> 사용 허가> <사용 허가 android : 이름 = "android.permission.MODIFY_AUDIO_SETTINGS"><사용 허가> –
또한 일반적으로 LogCat의'SecurityException' 항목은 여러분이 누락 된 권한을 구체적으로 알려줍니다. – CommonsWare