Note that there are some explanatory texts on larger screens.

plurals
  1. POOFF_HOOK STATE is never invoked for outgoing and incoming calls
    text
    copied!<p>I have written a BroadcastReceiver to detect outgoing and incoming calls. I am monitoring the network status when the user is on call (i.e when the phone state is off_hook). unfortunately off_hook state is not getting invoked for both incoming and outgoing calls.</p> <p>Here is the BroadcastReceiver:</p> <pre><code>public class BroadcastReceiverImpl extends BroadcastReceiver{ private ConnectivityManager connectivityManager; private TelephonyManager telephonyManager; private NetworkInfo networkInfo; private String networkStauts = "Not connected !!"; //java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime(). @Override public void onReceive(final Context context, Intent intent) { Toast.makeText(context, "Inside onReceive Method !!", Toast.LENGTH_SHORT).show(); connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); networkInfo = connectivityManager.getActiveNetworkInfo(); final Intent activityIntent = new Intent(context, ActivityImpl.class); telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(new PhoneStateListener(){ @Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_RINGING: Toast.makeText(context, "Call State Ringing !!", Toast.LENGTH_SHORT).show(); break; case TelephonyManager.CALL_STATE_OFFHOOK: Toast.makeText(context, "Call State Offhook !!", Toast.LENGTH_SHORT).show(); while (networkInfo!=null &amp;&amp; networkInfo.isConnectedOrConnecting()) { networkStauts = "Network Connected"; try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } break; case TelephonyManager.CALL_STATE_IDLE: Toast.makeText(context, "Call State Idle !!", Toast.LENGTH_SHORT).show(); activityIntent.putExtra("networkStatus", networkStauts); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(activityIntent); abortBroadcast(); break; default: break; } super.onCallStateChanged(state, incomingNumber); } }, PhoneStateListener.LISTEN_CALL_STATE); } } </code></pre> <p>Every time the call is over I am displaying the network status via an activity. But unfortunately it is displaying " Not connected !! " for every call (outgoing/incoming). Please let me know what the problem is.</p> <p>my manifest file:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.monitornetwork_v10" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.activity.NetworkMonitorActivityImpl"&gt;&lt;/activity&gt; &lt;receiver android:name="com.example.broadcastreceiver.BroadcastReceiverImpl" android:enabled="true" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.ACTION_PHONE_STATE_CHANGED" /&gt; &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt; &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt; &lt;action android:name="android.intent.action.ANSWER" /&gt; &lt;action android:name="android.intent.action.PHONE_STATE" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
 

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