Raw sound file as ringtone

by Sonic » Fri, 12 Mar 2010 01:17:08 GMT

Sponsored Links
 Hi all,

I am using the following code trying to pull an .mp3 or .ogg file from
my raw directory and saving it to the sd card and activating it as a
ringtone. Although, it keeps failing for some reason or another and
doesnt actually copy the new file to the sdcard.

Any ideas please?

    public boolean saveas(int ressound){
         byte[] buffer=null;
         InputStream fIn =
         int size=0;

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

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

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

         FileOutputStream save;
         try {
          save = new FileOutputStream(path+filename);
         } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          return false;
         } catch (IOException e) {
          // TODO Auto-generated catch block
          return false;

         sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,

         File k = new File(path, filename);

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

         //Insert it into the database

         return true;


Raw sound file as ringtone

by BOlivier » Fri, 12 Mar 2010 05:11:50 GMT

I used a similar method in TapSound (on android market).
Didn't you forget android.permission.WRITE_EXTERNAL_STORAGE ?


Sponsored Links

Other Threads

1. getting error while including the library..

I am trying to include a library in a sample application & i am
calling native methods from Java App.While trying to include the
library i'm getting following errors:

02-21 07:11:23.733: ERROR/AndroidRuntime(303): Caused by:
java.lang.UnsatisfiedLinkError: Library hello-jni not found

Can anyone please tell me why i am getting this error?


2. Can't install ADT on Eclipse 3.6.1 OSX

I am having a really hard time installing ADT for Eclipse (plain jane)
3.6.1 on OSX 10.6.6

Here is what I've done:

1. Installed Eclipse 10.6.1 to /Applications
2. Updated Eclipse
3. Installed latest Android SDK to /Developer/SDKs/
4. Ran tools/android update sdk - updated to latest a-ok
5. Followed instructions on official site to install ADT
6. Installing gets stuck on the following url:

I have tried with older versions of Eclipse and run into the same
issue. This is very frustrating, obviously the URL above is 404, so
I'm not sure what's up?

Thanks for any help.

java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/xxxx/.eclipse_keyring -
Command-line arguments:  -os macosx -ws cocoa -arch x86 -keyring /
Users/xxxx/.eclipse_keyring -showlocation


3. Developing for tablets

4. Related to calender access

5. Cannot fetch information from internet

6. Suggest some Android Projects

7. Deploying Application into Device