Reputation: 151
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...
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...
Please let me know how to achieve this... Thanks in advance.. :-)
my code...
BroadcastReceiver 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();
}
}
My Manifest File
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- <uses-permission android:name="android.permission.INTERNET"/> -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.abc.activity.NetworkStatusActivity"></activity>
<receiver android:name="com.abc.broadcastreceiver.MoniterNetworkStatus"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.ANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
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...
Please let me know how to achieve this... Thanks in advance.. :-)
Upvotes: 0
Views: 372
Reputation: 1963
You need to register another receiver to accept ACTION_PHONE_STATE_CHANGED. This may be a duplicate of Detecting outgoing call and call hangup event in android
Upvotes: 1