0

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...

  1. 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.. :-)

4

1 に答える 1

1

ACTION_PHONE_STATE_CHANGED を受け入れるには、別の受信者を登録する必要があります。これは、Android で発信コールとコール ハングアップ イベントを検出するのと重複している可能性があります。

于 2013-02-28T10:59:01.887 に答える