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 9274223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:18:19+00:00 2026-06-18T16:18:19+00:00

I am trying to play a ringtone selected by the user. When I use

  • 0

I am trying to play a ringtone selected by the user.

When I use this code:

RingtoneManager ringtoneManager = new RingtoneManager(this);
Uri uri = ringtoneManager.getRingtoneUri(position);

if(uri == null) {
    Log.d("ALARM", "uri is null");
}

try {
    mediaPlayer.setDataSource(getApplicationContext(), uri);
    mediaPlayer.prepare();  
    mediaPlayer.setLooping(true);
    mediaPlayer.start();
} catch (Exception e) {
    // Handle exception
}

I get “uri is null” and nothing happens, however if I put in an empty for loop beforehand like this:

for(int i = 0; i < ringtoneManager.getCursor().getCount(); ++i) {
//WTF
}

RingtoneManager ringtoneManager = new RingtoneManager(this);
Uri uri = ringtoneManager.getRingtoneUri(position);

if(uri == null) {
    Log.d("ALARM", "uri is null");
}

try {
    mediaPlayer.setDataSource(getApplicationContext(), uri);
    mediaPlayer.prepare();  
    mediaPlayer.setLooping(true);
    mediaPlayer.start();
} catch (Exception e) {
    // Handle exception
}

The uri is not null and the ringtone plays…

Can anyone explain what is going on here, and what I am supposed to do to avoid this hack?

Thanks

  • 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-06-18T16:18:20+00:00Added an answer on June 18, 2026 at 4:18 pm

    RingtoneManager has two constructors. One of them takes in a Context and the other takes an Activity. According to the docs, the one that takes an Activity will manage the cursor for you. The one that takes a Context will not.

    If the docs are to be believed, sounds like your this is not an Activity, and thus, the RingtoneManager instance you are getting is not managing the cursor and is expecting you to call getCursor().

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

Sidebar

Related Questions

i am trying folling code into android tv=(TextView) findViewById(R.id.ringtone); if (!hasErrors) { setListAdapter(new ArrayAdapter<String>(FindFilesByType.this,
What i m trying to do is get the selected ringtone from the user,
I am trying to play a ringtone which is selected from a RingtonePreference. How
I've been trying to use SoundPool to play the default ringtone without success. In
So I'm trying to play a video and the following code has worked for
I am trying to play Media Item that selected from UITableView in iOS. I
I am trying to play a .wav file using Audio Toolbox. I have this
While trying to play video using media player, I am getting this error: Unable
I'm trying to play with image resizer and I got the following code if
Hi i am trying to play many sounds using AVAudioPlayer and foundation. The code

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.