Refreshing Ringtone List


  1. itzdiceman

    itzdiceman New Member

    I am attempting to allow a user to save raw audio from my app to their SD card. Then in turn select that audio as a ring tone.

    My code:
    ------------------------------------------------------
    InputStream fIn = getBaseContext().getResources().openRawResource(clipID);
    int size = fIn.available();
    byte[] buffer = new byte[size];
    fIn.read(buffer);
    fIn.close();

    File rtNew = new File(
    "/sdcard/XYZ/Ringtones/"
    + ((Button) findViewById(buttonID)).getText()
    + ".ogg");

    FileOutputStream rtFOS = new FileOutputStream(rtNew);
    rtFOS.write(buffer);
    rtFOS.flush();
    rtFOS.close();
    -------------------------------------------------------
    buttonID is the int from R.id.buttonX and clipID is R.raw.clipX. The directory /sdcard/XYZ/Ringtones has been created previously in the application. I can confirm that the directory and the file are created using ASTRO.

    I've tried several variations on this code(which is why rtNew is a separate object). Including using /sdcard/ringtones and using all variations of case sensitive directories and file names.

    No matter what I try I cannot get the audio clip to appear in the "Settings->Sound & display->Phone ringtone" list.

    Here's the EXCEPTION:
    -I allow my app to create the directories and the file
    -confirm with ASTRO that they've been created
    -confirm that it IS NOT in the ring tones list
    -rename the file with ASTRO without changing the file name
    -then the file appears in the ring tones list

    This exception adds the file to the ringtones list even in a directory /sdcard/XYZ/ringtones. I've also tried rtNew.renameTo after writing the file. This did not work either.

    Has anyone experienced this or have a solution?

    Thanks.

    Advertisement
    :
  2. KeithG

    KeithG Well-Known Member

    Try this as a test.

    Save the file to your expected directory... /sdcard/xyz/ringtones or whatever.

    Plug the phone into your computer. And mount the sdcard. Browse ... then re-mount the sdcard.

    See if your audio file is now within the ringtones list?

    Unless your telling the lower layers about the new file, the android api has no idea you just created a new media file. You might need to tell the media provider that you have a new file for it to include.

    Try this portion of the api

    Its just a guess :)
  3. itzdiceman

    itzdiceman New Member

    Awesome.

    Thanks a lot. MediaScanner worked perfectly.
  4. ajaypradhan

    ajaypradhan New Member

    It is possible on android which version?. Can u help me.
Loading...

Share This Page