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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:29:49+00:00 2026-05-26T14:29:49+00:00

I am testing simple alarm application. In firstactivity I set alarm with ringtone which

  • 0

I am testing simple alarm application. In firstactivity I set alarm with ringtone which is picked from Ringtonemanger, for that I used setRing() method. Then through intent I passed it to Broadcast reciever,But when alarm invoked at specific time then at player.setAudioStreamType(AudioManager.STREAM_ALARM) ** it throws **NULL pointer exception .Anyone has idea??

private void setRing()
{
    intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,  RingtoneManager.TYPE_ALL);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);

    this.startActivityForResult(intent, 5);

}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent)
{
    if (resultCode == Activity.RESULT_OK && requestCode == 5)
    {
         Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

         if (uri != null)
         {
             this.chosenRingtone = uri.toString();
         }
         else
         {
             this.chosenRingtone = null;
         }

     }            




public class GroupsCheckAlarmReceiver extends BroadcastReceiver {    

 MediaPlayer mMediaPlayer ;
 MediaPlayer player;
 Context context1;
 Uri uri=null;

@Override
public void onReceive(final Context context, Intent intent) {
     Toast.makeText(context, "Alarm success", Toast.LENGTH_LONG).show();
     String struri=intent.getStringExtra("uristr");
     Log.v("value of ring",struri);
     uri=Uri.parse(struri);
     context1=context;
     try {
        callringtone();
    } catch (IllegalArgumentException e) {

        e.printStackTrace();
    } catch (SecurityException e) {

        e.printStackTrace();
    } catch (IllegalStateException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

}
private void callringtone() throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
     mMediaPlayer = new MediaPlayer();
     mMediaPlayer.setDataSource(context1,uri);

     final AudioManager audioManager = (AudioManager)context1.getSystemService(Context.AUDIO_SERVICE);

     if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
                player.setAudioStreamType(AudioManager.STREAM_ALARM);
                player.setLooping(true);
                player.prepare();
                player.start();
      }

     if(uri == null){

         uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
         if(uri== null){ 

             uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);               
         }

     }

  }
}
  • 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-26T14:29:50+00:00Added an answer on May 26, 2026 at 2:29 pm

    You never initialize your player variable. It’s null throughout the entire existence of your Broadcast receiver. So when you call setAudioStreamType() on it, you get your null pointer exception. You don’t use the player variable anywhere else in your broadcast receiver, and I think you actually meant to call all those methods in your if block on mMediaPlayer. So you could solve your problem by calling all your methods on that object instead, like so:

     if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mMediaPlayer.setLooping(true);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am testing a simple method which works fine for images with the HTTP
I have the following JUnit test. The method that I'm testing is quite simple,
I am testing a simple query to get data from an AS400 database. I
I am writing a simple framework for testing WinForm apps, which is running in
I have a very simple .net application for testing SMTP on .net. But i
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I want a simple testing shell script that launches a program N times in
I was testing this (nice) simple form from CSS Tricks. In a website hosted
I am testing a simple threadpool solution before I put it in my application,
I am testing a simple multicast application on linux. I got it working on

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.