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. What happens when network (GPRS) is not enabled, and you try to open connection?

I've been wondering this too.  I guess I assumed that if an
application has permissions in the manifest that the device will
automatically connect without prompting.



--~--~---------~--~----~------------~-------~--~----~

2. Content Providers and Network Requests

Hello,
As per the subject, i am making an app that is dependent on data that
comes from a network request.
I was using the UserTask class (Made by Mr. Romain Guy) to make the
network calls and get my data and everything worked.

But now, i want the data from this app to be available to other apps
as well and thus, the only way that data could be shared between
applications is by using a content provider (thats what i have read so
far).

My question was: Is it possible to use a thread or the UserTask class
inside a Content Provider and if yes, then since the request to the
server can take a long time, how do we change the query method of the
content provider to handle such a delay as it is suppose to return a
Cursor object.

In my initial approach, i was using a listener that took care of
updating the Application when the data was available but i am not
aware of a way to use a listener with a Content Provider.

Any help or ideas would be helpful.

Thanks

- Kavik
--~--~---------~--~----~------------~-------~--~----~

3. network monitoring information access

4. Providers Network Status In Persentage..Is It Possible??

5. Cannot connect to Wireless (wifi) unless Settings for Network set to Channel 1!

6. UK G1 Update available

7. WiFi within of emulator