如何在没有删除的情况下将mp3歌曲更新为铃声,插入

时间:2016-12-23 12:28:59

标签: android android-contentprovider

我试图将mp3歌曲更新为铃声。

RingtoneManager ringtoneManager = new RingtoneManager(Album_fragment.this.getActivity());

        String str_song_name = "";
        try{
            str_song_name =  Player_screen_main_activity.list_all_songs.get(position_ringtone).get("display_name");
        }catch (Exception e){
            e.printStackTrace();
        }

        if (lang.equalsIgnoreCase("phone")) {
            try {       

                File ringFile = new File(Player_screen_main_activity.list_all_songs.get(position_ringtone).get("data"));

                //File ringFile = new File(list_all_songs2.get(position_ringtone).get("data"));

                ContentValues values = new ContentValues();
                values.put(MediaStore.MediaColumns.DATA, ringFile.getAbsolutePath());
                //values.put(MediaStore.MediaColumns.TITLE, "ring_Phone_MusicCutter");


                values.put(MediaStore.MediaColumns.TITLE, str_song_name);

                values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
                values.put(MediaStore.MediaColumns.SIZE, ringFile.length());
                values.put(MediaStore.Audio.Media.ARTIST, com.musicplayer.player.mp3cutter.R.string.app_name);
                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, true);
                Uri uri = MediaStore.Audio.Media.getContentUriForPath(ringFile.getAbsolutePath());

              //  getActivity().getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + ringFile.getAbsolutePath() + "\"", null);

             //   Uri newUri = getActivity().getContentResolver().insert(uri, values);

               getApplicationContext().getContentResolver().update(uri , values, selection, arg);
                try {
                    ringtoneManager.setActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_RINGTONE, uri );
                } catch (Throwable t) {

                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

无法更新到手机铃声,我已登记设置Phone ringtone名称,而不是使用设置的铃声名称更新。

0 个答案:

没有答案