0

I wonder is there have a way to set mp3 files in ListView as default ringtone?

Please share me a link to learn.

SopheakVirak
  • 961
  • 6
  • 14
  • 36
  • 1
    Check this.It has a solution to your question. [Here](http://stackoverflow.com/questions/1271777/how-to-set-ringtone-in-android-from-my-activity) – Abhilasha Jul 04 '12 at 06:39

1 Answers1

1

try as for setting mp3 file as Ringtone:

 public void setMyRingtone(File file)  // pass mp3 file path for ringtone
         {  
           ContentValues values = new ContentValues();  
           values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());  
             values.put(MediaStore.MediaColumns.TITLE, file.getName());  
             values.put(MediaStore.MediaColumns.SIZE, file.length());  
             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);  

             Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());  
             Uri newUri = contextx.getContentResolver().insert(uri, values);  
             RingtoneManager.setActualDefaultRingtoneUri(contextx, RingtoneManager.TYPE_RINGTONE, newUri);  
         } 

manifast.xml Permission:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • dear Imran Khan, I already tried this but it's only one mp3, So how can I set it from ListView. Let's say I have 10 ringtones file listed in ListView to allow user to select. what should I do? I really appreciate for your help. – SopheakVirak Jul 04 '12 at 06:53
  • 1
    @but you can set one ringtone at a time right?if you want set default ringtone only means one ringtone then just call setMyRingtone method from onItemClick of Listview and pass path of selected ringtone path and if you want to add all mp3 files in default ringtone list then just (MediaStore.MediaColumns.DATA insert all ringtone in – ρяσѕρєя K Jul 04 '12 at 06:58
  • @SopheakVirak : i think you understand what i want to say?? – ρяσѕρєя K Jul 04 '12 at 07:02
  • 1
    Dear Imran Khan, I am trying it again. I will answer you after I done. – SopheakVirak Jul 04 '12 at 07:07
  • Dear Imran Khan, I tried so many time but still not come out the result. Do you have full code this? sorry for disturb you. – SopheakVirak Jul 04 '12 at 08:25