简体   繁体   English

将我的res / raw包中的mp3添加到Android的铃声列表中

[英]Adding a mp3 from my res/raw of package into the Ringtone List of Android

How do I add the mp3 in my res/raw of application into the Android ringtone list. 如何在应用程序的res / raw中将mp3添加到Android铃声列表中。 I dont want to play it, but to add it into the ringtone list. 我不想播放,但要将其添加到铃声列表中。 Been reading some topics but still very confused. 一直在阅读一些话题,但仍然很困惑。

Just add all your ringtones to some folder (folder must be created first) 只需将所有铃声添加到某个文件夹(必须先创建文件夹)

InputStream in = getResources().openRawResource(R.raw.ringtone1);
FileOutputStream out = new FileOutputStream("/mnt/sdcard/media/ringtones/ringtone1.mp3");
byte[] buff = new byte[1024];
int read = 0;

try {
   while ((read = in.read(buff)) > 0) {
      out.write(buff, 0, read);
   }
} finally {
     in.close();

     out.close();
}

Don't forget to add permission 不要忘记添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

If you want to pick only notifications from Ringtone Picker you should copy your raw mp3 file to notification folder. 如果您只想从“铃声选择器”中选择通知,则应将原始mp3文件复制到通知文件夹。 It's naming convention. 这是命名约定。 Then when you set up Ringtone Picker like this 然后当您像这样设置铃声选择器时

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
    RingtoneManager.TYPE_NOTIFICATION);

You will see your file only if it's located in folder which name is notifications . 仅当文件位于名称为notifications的文件夹中时,您才会看到文件。

UPDATED: 更新:

Forgot to mention that you should scan your sdcard after adding some new ringtones/notifications. 忘了提一下,您应该在添加一些新的铃声/通知后扫描sdcard。 Like this for example: 例如:

    mContext.sendBroadcast (
            new Intent(Intent.ACTION_MEDIA_MOUNTED,
                    Uri.parse("file://" + Environment.getExternalStorageDirectory()))
    );

If you do not mind the file being copied, then an easy way to have it included is to have your app drop the file on the SD card under: 如果您不介意要复制的文件,则包含该文件的一种简单方法是让您的应用程序将文件拖放到SD卡上的以下位置:

[/sdcard]/media/ringtones [/ sdcard] /媒体/铃声

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM