Hey people, i have problem.Code below is to set ringtone in my app.It
is copying song from app to SDC and call function to set
ringtone.There is no error in code and its coping good song but not
setting  ringtone :( .Please see if there is something wrong and
comment.. Thanks

////////////////////////////////////////////////////////////// program
that call a function "saveas"

if (saveas(R.drawable.song)) {

                                String path = "/sdcard/Ringtones/";
                                String filename = "song" + ".mp3";
                                sendBroadcast(new 
Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                                                Uri.parse("file://" + path + 
filename)));

                                File ringPath = new File(path, filename);

                                ContentValues values = new ContentValues();
                                values.put(MediaStore.MediaColumns.DATA,
                                                ringPath.getAbsolutePath());
                                values.put(MediaStore.MediaColumns.TITLE, 
"exampletitle");
                                values.put(MediaStore.MediaColumns.MIME_TYPE, 
"audio/mp3");
                                values.put(MediaStore.Audio.Media.DURATION, 
500);
                                values.put(MediaStore.Audio.Media.ARTIST, 
"cssounds ");
                                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(ringPath
                                                .getAbsolutePath());

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

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

                                String str = "Rington postavljen..";

                                Toast.makeText(getBaseContext(), str, 
Toast.LENGTH_SHORT)
                                                .show();
}

/////////////////////////////////////////////////////////// program
"saveas"- coping song from app to SDC

public boolean saveas(int ressound){
                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) {

                 return false;
                }

                String path="/sdcard/Ringtones/";
                String filename="song"+".mp3";

                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) {

                 return false;

                }
                catch (IOException e) {

                 return false;
                }

                return true;
               }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to