Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Invoke/Start an application when a call is ended?
    primarykey
    data
    text
    <p>The code that I am presently using is as follows:</p> <p>My <strong>main class</strong></p> <pre><code> 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); } } </code></pre> <p>the <strong>CustomPhoneStateListener class</strong></p> <pre><code> 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; } } } </code></pre> <p>and the Android Manifest file as:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.call" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;receiver android:name=".Index" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PHONE_STATE"/&gt; &lt;action android:name="android.view.InputMethod" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.CALL_PHONE"/&gt; &lt;/manifest&gt; </code></pre> <p>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 <strong>Intent</strong> or by using the <strong>Package_Manger</strong> I am not able to shift to the next app.</p> <p>The log_cat message returned when trying to execute the code for invoking the app:</p> <pre><code> 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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload