android ringtones - how to add ringtones getting from URL path
<p>I wonder is there any way to set ringtones that get from url path when user long click on ringtones name in Activity.</p>

<p>Bellow code i tried to change filnal path from R.raw.sound1 to URL path, but still can't.</p>

<p>Anyone can give me a clue of how to set ringtone getting file from URL?</p>

<h1>Here is my code</h1>

<pre><code>final MediaPlayer ring01 = MediaPlayer.create(this, R.raw.sound1);

// play sound files on clicks
    Button s01 = (Button) findViewById(R.id.btnring01); 
    s01.setText(this.getString(R.string.title01));
    s01.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v)
        {
    try 
            {
        ring01.prepare();
    }
            catch (IllegalStateException e)
            {
        e.printStackTrace();
    } 
            catch (IOException e)
            {
        e.printStackTrace();
        }
    ring01.start();             
    }
});
    registerForContextMenu(s01);

public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  
super.onCreateContextMenu(menu, v, menuInfo);  
        menu.setHeaderTitle("Save as...");  
        menu.add(0, v.getId(), 0, "Tab Here To Save As Ringtone");    
    }  

@Override  
public boolean onContextItemSelected(MenuItem item) {  
    if(item.getTitle()=="Tab Here To Save As Ringtone"){function1(item.getItemId());}  
    else {return false;}  
return true;  
}

public boolean function1(int ressound){

    String soundname = "";

    switch(ressound)
    {
        case R.id.btnring01:
        ressound=R.raw.aftermath;
        soundname = (this.getString(R.string.title01));
        break;
    }

  //and so on and so on.....
  byte[] buffer=null;
   InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
   int size=0;

   try {
   size = fIn.available();
   buffer = new byte[size];
   fIn.read(buffer);
   fIn.close();
   } catch (IOException e) {
   // TODO Auto-generated catch block
   return false;
   }

   String path="/sdcard/media/audio/ringtones/";
   String filename=soundname+".ogg";

   boolean exists = (new File(path)).exists();
   if (!exists){new File(path).mkdirs();}

   FileOutputStream save;
   try {
   save = new FileOutputStream(path+filename);
   save.write(buffer);
   save.flush();
   save.close();
   } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   return false;
   } catch (IOException e) {
   // TODO Auto-generated catch block
   return false;
   }
 File k = new File(path, filename);

   ContentValues values = new ContentValues();
   values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
   values.put(MediaStore.MediaColumns.TITLE, soundname);
   values.put(MediaStore.MediaColumns.SIZE, 215454);
   values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
   values.put(MediaStore.Audio.Media.ARTIST, "Sokun Kanha");
   values.put(MediaStore.Audio.Media.DURATION, 230);
   values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
   //values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
   //values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
   //values.put(MediaStore.Audio.Media.IS_ALARM, true);
   //values.put(MediaStore.Audio.Media.IS_MUSIC, false);
   values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
   values.put(MediaStore.Audio.Media.IS_ALARM, false);
   values.put(MediaStore.Audio.Media.IS_MUSIC, false);
</code></pre>
