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

The Archive Base Latest Questions

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

HI, I am in a situation that I need to display notification when call

  • 0

HI,
I am in a situation that I need to display notification when call arrives. For this I am using broadcast receiver. Code is below

public class MyPhoneStateListener extends PhoneStateListener {
    public Context context;
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        // TODO Auto-generated method stub
        super.onCallStateChanged(state, incomingNumber);
        switch(state){
        case TelephonyManager.CALL_STATE_IDLE:
            NotificationManager notifier = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

            //Get the icon for the notification
            int icon = R.drawable.icon;
            Notification notification = new Notification(icon,"Simple Notification",System.currentTimeMillis());

            //Setup the Intent to open this Activity when clicked
            Intent toLaunch = new Intent(context, main.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, toLaunch, 0);

            //Set the Notification Info
            notification.setLatestEventInfo(context, "Hi!!", "This is a simple notification", contentIntent);

            //Setting Notification Flags
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_INSISTENT;
          //  notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
            //Send the notification
            notifier.notify(0x007, notification);
            Log.d("CALL", "IDLE");
        break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
          Log.d("DEBUG", "OFFHOOK");
        break;
        case TelephonyManager.CALL_STATE_RINGING:

          Log.d("DEBUG", "RINGING");
        break;
        }
    }

}

Now problem is that sound for the notification is not playing but notification is being displayed correctly. Can anyone shed light on it please why notification sound is not being played?

  • 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-22T22:38:26+00:00Added an answer on May 22, 2026 at 10:38 pm

    I ended up playing sound manually via media player. Code Now Looks like

    public class MyPhoneStateListener extends PhoneStateListener {
        public Context context;
        public static final String PREFS_NAME = "ealertprefs";
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            // TODO Auto-generated method stub      
            switch(state){
            case TelephonyManager.CALL_STATE_IDLE:                     
                Log.v("CALL", "IDLE");
            break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
              Log.d("DEBUG", "OFFHOOK");
            break;
            case TelephonyManager.CALL_STATE_RINGING:
              if(call_from_elist(incomingNumber)) {
                  wake_up_phone();
                  send_notification();
                  create_sound();
              }
              Log.d("DEBUG", "RINGING");
            break;
            }
        }
        private boolean call_from_elist(String number) {
            return true;
        }
        private void wake_up_phone() {
            AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
            am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        private void send_notification(){
            NotificationManager notifier = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);                
            int icon = R.drawable.icon;
            Notification notification = new Notification(icon,"Simple Notification",System.currentTimeMillis());        
            Intent toLaunch = new Intent(context, main.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, toLaunch, 0);        
            notification.setLatestEventInfo(context, "Hi!!", "This is a simple notification", contentIntent);        
            notification.flags |= Notification.FLAG_AUTO_CANCEL;                              
            notifier.notify(0x007, notification);
        }
        private void create_sound() {
            Uri alert;
            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
            String ringtone = settings.getString("ringtone_uri", "");
            if(ringtone.equals("")) {
                alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            }
            else {
                alert = Uri.parse(ringtone);
            }
    
            MediaPlayer mMediaPlayer = new MediaPlayer();
            try {
                mMediaPlayer.setDataSource(context, alert);
                //final AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
                //if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) {
                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
                    //mMediaPlayer.setLooping(true);
                    mMediaPlayer.prepare();
                    mMediaPlayer.start();
                //}
            }
            catch(IOException e) {
                Log.v("CALL", e.getMessage());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in this situation that i need a list of lists. for instance i
Situation: I need to make an imap client (using java mail api) that if,
I am in kind of situation that I need to start with a tab
Situation: I have a simple XML document that contains image information. I need to
I have a situation where I need to display a double value rounded to
Env: .NET 1.1 I got into this situation. Where I need to give a
I'm in a situation where I need to display a tree. However some of
I'm trying to get some code going that lets me display raw trackpad data
I'm running a long simulation in MATLAB that I've realized I need to stop
So odd situation that I ran into today with OrderBy: Func<SomeClass, int> orderByNumber =

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.