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

  • Home
  • SEARCH
  • 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 6798417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:43:39+00:00 2026-05-26T18:43:39+00:00

The code that I am presently using is as follows: My main class public

  • 0

The code that I am presently using is as follows:

My main class

  public class Index extends  BroadcastReceiver{ 

        @Override
        public void onReceive(Context context, Intent intent) {

            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
        }
    }

the CustomPhoneStateListener class

    public class CustomPhoneStateListener extends PhoneStateListener {

        public  Activity activ=new Activity(){
            public void startActivity(Intent i) {}
            };
            Context context; 
        public CustomPhoneStateListener(Context context) {
            super();
            this.context = context;
        }
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
           switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:

                Toast.makeText(context, "call has ended", Toast.LENGTH_SHORT).show();
    // The process to transfer to the next application. 
                    Intent i = new Intent(Intent.ACTION_MAIN);
                PackageManager manager = activ.getPackageManager();
i = manager.getLaunchIntentForPackage("com.timetracker.app");// package  name for my new app
                i.addCategory(Intent.CATEGORY_LAUNCHER);
                activ.startActivity(i);
                break;
        case TelephonyManager.CALL_STATE_OFFHOOK:

                Toast.makeText(context, "Phone call has taken", Toast.LENGTH_SHORT).show();
                break;
            case TelephonyManager.CALL_STATE_RINGING:

                //when Ringing
                Toast.makeText(context, "Phone is ringing", Toast.LENGTH_SHORT).show();
                break;
                default:
                break;
            }
        }
    }

and the Android Manifest file as:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.call"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
                <receiver android:name=".Index" >
                  <intent-filter>
               <action android:name="android.intent.action.PHONE_STATE"/>
               <action android:name="android.view.InputMethod" /> 
                </intent-filter>
                </receiver>
</application>

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE"/> 
</manifest>

By using the above code I am able to get the toast message for the respective actions that I am performing ,but I am not able to give any Intent or by using the Package_Manger I am not able to shift to the next app.

The log_cat message returned when trying to execute the code for invoking the app:

 D/AndroidRuntime(312): Shutting down VM
: W/dalvikvm(312): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
 FATAL EXCEPTION: main
  E/AndroidRuntime(312): java.lang.NullPointerException 
  E/AndroidRuntime(312):    at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:85)
  E/AndroidRuntime(312):    at com.android.call.CustomPhoneStateListener.onCallStateChanged(CustomPhoneStateListener.java:39)
  E/AndroidRuntime(312):    at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:319)
  E/AndroidRuntime(312):    at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(312):    at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime(312):    at android.app.ActivityThread.main(ActivityThread.java:4627)
  E/AndroidRuntime(312):    at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(312):    at java.lang.reflect.Method.invoke(Method.java:521)
  E/AndroidRuntime(312):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   E/AndroidRuntime(312):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   E/AndroidRuntime(312):   at dalvik.system.NativeStart.main(Native Method)
  • 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-26T18:43:39+00:00Added an answer on May 26, 2026 at 6:43 pm

    It looks like the problem is coming from the use of active declared like this:

        public  Activity activ=new Activity(){
            public void startActivity(Intent i) {}
        };
    

    Here you’re creating a new Activity without a context. Maybe you should just pass the Activity right into your CustomPhoneStateListener instead of the Context. Or use the context to get the PackageManager:

    PackageManager manager = context.getPackageManager();

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

Sidebar

Related Questions

I am using this code to check that array is present in the HashMap
The code that I want to write is like this: void MethodOnThreadA() { for
Sample code that shows how to create threads using MFC declares the thread function
My code that I tried is as follows: var dataO = new Object(); dataO.numberId
Below I am posting some code that I am using to try to set
Code that is untestable really annoys me. The following things make oo-code untestable: global
I'm maintaining some code that uses a *= operator in a query to a
I'm writing C# code that uses the windows IP Helper API. One of the
I've got C# code that accesses MySQL through ODBC. It creates a transaction, does
I have some template code that I would prefer to have stored in a

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.