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 =
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="priceringtone"+".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;
         }

         sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.parse("file://"+path+filename)));

         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
 
this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()),
values);

         return true;
        }

--



Raw sound file as ringtone

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


 Hi.
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..

hi,
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:
http://www.eclipse.org/downloads/download.php?format=xmlfile=/releases/helios/201006230900/aggregate/protocol=httpcountryCode=ustimeZone=-5format=xml

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.

------
eclipse.buildId=M20100909-0800
java.version=1.6.0_22
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/xxxx/.eclipse_keyring -
showlocation
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