setting ringtone through android application
<p>I am trying to set a ringtone through android application. I have the following piece of code to do this;</p>

<pre><code>public boolean saveas(int ressound){
02   byte[] buffer=null;
03   InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
04   int size=0;
05   
06   try {
07    size = fIn.available();
08    buffer = new byte[size];
09    fIn.read(buffer);
10    fIn.close();
11   } catch (IOException e) {
12    // TODO Auto-generated catch block
13    return false;
14   }
15   
16   String path="/sdcard/media/audio/ringtones/";
17   String filename="examplefile"+".wav";
18   
19   boolean exists = (new File(path)).exists();
20   if (!exists){new File(path).mkdirs();}
21   
22   FileOutputStream save;
23   try {
24    save = new FileOutputStream(path+filename);
25    save.write(buffer);
26    save.flush();
27    save.close();
28   } catch (FileNotFoundException e) {
29    // TODO Auto-generated catch block
30    return false;
31   } catch (IOException e) {
32    // TODO Auto-generated catch block
33    return false;
34   }   
35   
36   sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));
37   
38   File k = new File(path, filename);
39   
40   ContentValues values = new ContentValues();
41   values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
42   values.put(MediaStore.MediaColumns.TITLE, "exampletitle");
43   values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
44   values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
45   values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
46   values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
47   values.put(MediaStore.Audio.Media.IS_ALARM, true);
48   values.put(MediaStore.Audio.Media.IS_MUSIC, false);
49   
50   //Insert it into the database
51   this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
52   
53   return true;
54  }  
</code></pre>

<p>I am a beginer to android programming so I am confusion.</p>

<p>I created a class by extending activity and create <code>onCreate()</code> method, so from   <code>onCreate()</code>  which function I have to call.</p>

<p>Thanks in advance.</p>

<p>NB: friends suggest me a simple book to learn basic and advanced android</p>
