【问题标题】:My added ringtone disappears when rebooting我添加的铃声在重启时消失了
【发布时间】:2013-01-23 16:36:13
【问题描述】:

我从原始文件中添加铃声,如下面的代码,它可以工作。 添加后,我可以打开 Android 系统铃声列表,它会出现在那里,所以我(或任何其他应用程序)可以使用它。 问题是,如果我重新启动手机,那么列表中的那个条目就消失了。 那么,有没有办法永久添加铃声呢? 谢谢

我使用此代码添加:

private void AddRingTone() //I assume that sdcard directory exists and it is empty
{  //We first copy the raw resource to sdcard:
   String sPath = Environment.getExternalStorageDirectory() + "/AnyPath"; //AnyPath already exists.        
   File newSoundFile = new File(sPath, "MyRingtone");
   Uri mUri = Uri.parse("android.resource://" + getPackageName()+ "/" + R.raw.myringtone);
   AssetFileDescriptor soundFile;
   try 
   {  soundFile= getContentResolver().openAssetFileDescriptor(mUri, "r");
   }catch (FileNotFoundException e)
   {  soundFile=null;   
      MessageBox("Cannot open " + mUri.toString());
   }
   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("RingtoneManager:\n" + io.toString());  
   }


   //Now we add it to the system list:
   ContentValues values = new ContentValues();
   values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
   values.put(MediaStore.MediaColumns.TITLE, "my ring tone");
   values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/oog");
   values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length());
   values.put(MediaStore.Audio.Media.ARTIST, "me");
   values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
   values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
   values.put(MediaStore.Audio.Media.IS_ALARM, false);
   values.put(MediaStore.Audio.Media.IS_MUSIC, false);
   Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
   Uri newUri = getContentResolver().insert(uri, values);

}

【问题讨论】:

    标签: android add ringtone


    【解决方案1】:

    它消失的原因是它没有存放在正确的地方!

    Android 关注媒体文件的官方地点位于/sdcard/media/audio/Ringtones/sdcard/media/audio/notifications,以最适合的为准!

    Android 对名为 AnyPath 的目录的了解为零,并且媒体扫描器不会拾取它!

    【讨论】:

    • 对不起,还是不行 :-( 我不知道我做错了什么
    • 是的,它正在工作。对不起,我不得不重新启动手机,但还要等待“搜索媒体......”的漫长过程。我认为它已经在系统区域中,因此不需要进行新的搜索。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    相关资源
    最近更新 更多