如何从我的活动中设置的铃声在Android中?我的、铃声、活动中、Android

由网友(血洗天下)分享简介:我试图找到一种方法,从我的Andr​​oid活动通过设置code一个新的默认铃声。I'm trying to find a way to set a new default ringtone by code from my Android activity.我已经下载铃声到字节组。推荐答案最后,我成功地设置默认...

我试图找到一种方法,从我的Andr​​oid活动通过设置code一个新的默认铃声。

I'm trying to find a way to set a new default ringtone by code from my Android activity.

我已经下载铃声到字节组

推荐答案

最后,我成功地设置默认铃声的一个,我下载。 下载code不低于在内,只需要怎样将其设置为默认铃声。

Finally, I managed to set the default ringtone to one that i downloaded. The download code is not included below, only what was needed to set it as default ringtone.

File k = new File(path, "mysong.mp3"); // path is a file to /sdcard/media/ringtone

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "My Song title");
values.put(MediaStore.MediaColumns.SIZE, 215454);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, "Madonna");
values.put(MediaStore.Audio.Media.DURATION, 230);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
Uri newUri = this.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
  myActivity,
  RingtoneManager.TYPE_RINGTONE,
  newUri
);  

反正,我不完全理解这是什么code在做什么。

Anyway, I do not totally understand what this code is doing.

的铃声管理器需要的URI是要被设置为新的铃声文件。但是,此URI不能直接像/sdcard/media/ringtones/mysong.mp3的SD卡。那不行!

The Ringtone manager needs a uri to the file that is to be set as new ringtone. But this uri can not be directly to the sdcard like "/sdcard/media/ringtones/mysong.mp3". That does not work!

您需要的是这可能是这样的文件的外部文件URI /外部/音频/媒体/ 46

What you need is the external file uri of the file which could be something like "/external/audio/media/46"

46是在MediaStore数据库中列的ID,所以这就是为什么你需要将SD卡的文件先添加到数据库中。

The 46 is the id of the column in the MediaStore database, so thats why you need to add the sdcard file into the database first.

总之,如何mediastore保持其IDS?这个数字可以得到非常高的,因为你这样做很多次。

Anyway, how does mediastore maintain its ids? This number can get really high, as you do this operation many times.

我是否需要删除此行我的自我?问题是,有些时候,我甚而不CONTROLL文件的删除,因为它可以直接从一个filebrowser的SD卡被删除。

Do i need to delete this row my self? Problem is that some times i dont even controll the deleting of the file since it can be deleted directly from the sdcard with a filebrowser.

阅读全文

相关推荐

最新文章