Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoking an activity from Broadcast Receiver
    primarykey
    data
    text
    <p>i am a beginner in android and i am developing an application where BrocastReceiver starts whenever the user makes a call... i am trying to monitor the network status inside the broadcast receiver... and i am trying to start the activity when the user hangs up the phone... but unfortunately it is giving me an error...please let me know how to do this... </p> <p>My broadcast receiver starts properly when the user make a call... but i do not know how to monitor the network inside the BroadcastReceiver when the user is on call.. and invoke the activity from the BroadcastReceiver when the user hangs up the phone...</p> <p>Please let me know how to achieve this... Thanks in advance.. :-)</p> <p>my code...</p> <ol> <li><p><strong>BroadcastReceiver Code</strong></p> <pre><code> public class MoniterNetworkStatus extends BroadcastReceiver{ private ConnectivityManager connectivityManager; private NetworkInfo info; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Monitering Network Status !!!", Toast.LENGTH_LONG).show(); boolean networkStatus = false; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); Intent activityIntent = new Intent(context, NetworkStatusActivity.class); // I am monitoring the network status as long as user is on call... while(telephonyManager.getCallState()!= TelephonyManager.CALL_STATE_IDLE){ info = connectivityManager.getActiveNetworkInfo(); if(info == null){ networkStatus = false; }else if(info.getType() == ConnectivityManager.TYPE_MOBILE){ networkStatus = info.isConnected(); }else{ networkStatus = false; } } //Putting the network details in to the activity. activityIntent.putExtra("operatorName", telephonyManager.getNetworkOperatorName()); activityIntent.putExtra("networkStatus", networkStatus); // starting the activity context.startActivity(activityIntent); abortBroadcast(); } } </code></pre> <p><strong>My Manifest File</strong></p> <p></p> <pre><code>&lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" /&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;!-- &lt;uses-permission android:name="android.permission.INTERNET"/&gt; --&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.abc.activity.NetworkStatusActivity"&gt;&lt;/activity&gt; &lt;receiver android:name="com.abc.broadcastreceiver.MoniterNetworkStatus" android:enabled="true" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt; &lt;action android:name="android.intent.action.ANSWER" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; </code></pre> <p></p></li> </ol> <p>My broadcast receiver starts properly when the user make a call... but i do not know how to monitor the network when the user is on call.. and invoke the activity when the user hangs up the phone...</p> <p>Please let me know how to achieve this... Thanks in advance.. :-)</p>
    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.
    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