0

我正在尝试使用这个:

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
4

1 回答 1

1

“android.permission.WRITE_SETTINGS”是你需要的。

于 2012-12-20T00:30:14.877 回答