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. Changing the width of an ImageView

Hi,

This looks too simple, but I can't figure out why it does not.

I have an ImageView inside a relative layout:

        <ImageView
                android:id="@+id/DRAG"
                android:layout_height="10dip"
                android:background="@drawable/drag_stroke"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_width="10dip">
        </ImageView>

In the code, I would like to change it's width: (in response to the
change of a seekBar)
Here's the code:


private void setWidthOfImage(imageWidthInPixel){
     final ImageView dragView  =  ( ImageView )
findViewById(R.id.DRAG );
    dragView.getLayoutParams().width = imageWidthInPixel ;            //
******** this does not execute****
}

It works only once (when called at initialization). but the same code
called again, from inside the loop of seekBar, enters with the correct
value, but does not execute the  getLayoutParams statement.

The seekBar correctly updates and provides the correct value. Inside
setWidthOfImage I can read the value to be correct. But the width does
not get updated.

Can a good soul shed light on this?


Thank you

Saied

-- 

2. how do I force sendDownUpKeyEvents(MEkeyEventCode) to complete

Hi,

I am developing a input method.  As recommended by google, am using
sendDownUpKeyEvents(someEventCode) for the key characters.

But in some circumstances this event does not get executed
immediately. I.e., I check the textfield  on which I just put a

sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER)

right after this command for the char behind the cursor, but CR has
not made it there yet.

This probably happens becuase sendDownUpKeyEvents is executed on the
SAME thread (and hence the "some circumstances" I alluded to earlier).

Is it a way to force execute this?

or is there any other way?

Thank you.

-- 

3. USB Video on an OMAP based board

4. Porting to FPGA (Newbie)

5. Google Market cancelling orders

6. OOS : How do you use google groups ?

7. WebView content fit display screen!!!