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. Advice For First (Simple?) Non-Tutorial Project

Greetings, fellow beginners!

First question: I've done the Hello World and notepad tutorials, as well as
run through the quick tutorial <http://www.youtube.com/watch?v=I6ObTqIiYfE>on
youtube by Dan Morril.  I've also read a bit of the Android fundamentals
materials.  Is this enough experience to make an application like the one
I'll describe below?

If not, what do you think I should read or try next?  If so,

The application I have in mind will be a counter triggered by users.  A user
will add themselves to the count, remove themselves from the count, and view
the count.

When a user adds or removes themself to the count...
- if possible, this will update the count on other instances for other
users/devices

That's my first step for now.  The UI will be a ListView showing the counts
that users have added themselves to (once I create the means to have one
count, I will easily be able to scale the app to have "n" counts).  There
will be a button to add and remove the user.

Sounds reasonable, right?  Please let me know if this sounds difficult,
especially where the multi-device communication (in updating the counter) is
concerned.  Know of a library that I'll have to use, or have some general
advice for this?  Tell me! :)

Thank you for reading!

-Danny

-- 

2. Ini bener kagak iklannya?

Tadi ada yg nyoba...lokasi tanjungduren ...1,2 mbps
Pdhl gw selama di sini, ga pernah telkomsel nyampe di atas 500 pdhl dah gw
akalin pake antene




Salam,

Lucky Sebastian

-- 
"Indonesian Android Community [id-android]"

3. Try the free AndroidShell app to speed you learning of Android programming

4. Update : WTS : Hp CDMA 1900 Smart

5. hp2 titipan temen ..

6. USB programming SDK?

7. Akhirnya....CM5 for Dream/Magic -> yup, its Eclair!!!