Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:04:25+00:00 2026-05-25T22:04:25+00:00

This has been changed from the original post. Basically what is happening is I

  • 0

This has been changed from the original post.

Basically what is happening is I have gotten this to display the ringtone in the ringtone list on the phone. It also selects it. In this code it plays the ringtone after it has been selected (I have taken it out to reduce the size). It seems to be playing the phones default ringtone. Any ideas why? Thanks

private void ringtone(int p){
    File newSoundFile = new File("/sdcard/media/ringtone", "raven.wav");
    Uri mUri = Uri.parse("android.resource://com.fs.hh/"+R.raw.raven);
    ContentResolver mCr = getContentResolver();
    AssetFileDescriptor soundFile;

    try {
           soundFile= mCr.openAssetFileDescriptor(mUri, "r");
       } catch (FileNotFoundException e) {
           soundFile=null;   
       }

       try {
          byte[] readData = new byte[1024];
          FileInputStream fis = soundFile.createInputStream();
          FileOutputStream fos = new FileOutputStream(newSoundFile);
          int i = fis.read(readData);

          while (i != -1) {
            fos.write(readData, 0, i);
            i = fis.read(readData);
          }

          fos.close();
          soundFile.close();
       } catch (IOException io) {
       }

       ContentValues values = new ContentValues();
       values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
       values.put(MediaStore.MediaColumns.TITLE, "my ringtone");
       values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
       values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length());
       values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
       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);

       Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
       mCr.delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newSoundFile.getAbsolutePath() + "\"", null);

       Uri newUri = mCr.insert(uri, values);



      RingtoneManager.setActualDefaultRingtoneUri(Soundboard.this, RingtoneManager.TYPE_RINGTONE, newUri);



}

I have also tried adding a / after ringtone and making it get the byte size. Neither have worked.

I have also tried this piece of code instead and it causes the same problem. It shows up selected in the notification section, but the sound being played is not the correct sound. It sounds like a default ringer.

private boolean setRingtone(int p){
    int ressound = whichSound(p); //The R.raw.sound
    String fileTitle = fileTitle(p); // sound
    String soundTitle = soundTitle(p); // Sound
    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/notification";
    String filename=fileTitle+".wav";

    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, soundTitle);
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
    values.put(MediaStore.Audio.Media.ARTIST, "HH");
    values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
    values.put(MediaStore.Audio.Media.IS_ALARM, false);
    values.put(MediaStore.Audio.Media.IS_MUSIC, false);

    //Insert it into the database
    Uri newUri= this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

    RingtoneManager.setActualDefaultRingtoneUri(
    this,
    RingtoneManager.TYPE_NOTIFICATION,
    newUri
    );

        return false;
      } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:04:26+00:00Added an answer on May 25, 2026 at 10:04 pm

    Here is what finally fixed it.

    private boolean setRingtone(int p){
        int ressound = whichSound(p);
        String fileTitle = fileTitle(p);
        String soundTitle = soundTitle(p);
        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=Environment.getExternalStorageDirectory().getPath()+"/media/ringtone/";
    
        String filename=fileTitle+".wav";
    
        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, soundTitle);
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
        values.put(MediaStore.Audio.Media.ARTIST, "");
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, false);
    
        //Insert it into the database
        Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
        getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
        Uri newUri = getContentResolver().insert(uri, values); 
        RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
    
    
    
        return false;
          }  
    

    In the path String by adding Environment.getExternatStorageDirectory().getPath() instead of just the sdcard it was actually able to play the sound and work properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been a rather problematic issue on numerous occasions. We have alot of
This has been driving me crazy for the past few minutes I have a
Edit: My original title has been sort of changed. I suspect the current title
This has been a problem that I haven't been able to figure out for
This has been an adventure. I started with the looping duplicate query located in
This has been driving me crazy for a few days. Why doesn't the following
This has been troubling me for a few years, and was recently exacerbated by
This has been asked before (question no. 308581) , but that particular question and
This has been confusing me for some time. With the advent of UTF-8 as
This has been one of the biggest obstacles in teaching new people ColdFusion. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.