application crashes while using a method of differ

2019-03-02 07:42发布

问题:

I am developing a SIP application for incoming and outgoing calls and i want to show AlertDialog on incoming call. For that i had put two buttons with dialog Accept and Reject. on pressing either one of this buttons application is crashes.

here is the code of my class and manifest files.


code for incomingCallReciever

public class IncomingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
    Intent nextpage = new Intent(context, IncomingCallPage.class);
    nextpage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(nextpage);
    mContext = context;

}

public void acceptCall() {
    incomingCall.sendDtmf(9);
    try {
        incomingCall.sendDtmf(9);
        incomingCall.answerCall(200);
        wtActivity.gototimer("i");
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    wtActivity.gototimer("i");
}

public void rejectCaLL() {
    try {
        incomingCall.endCall();
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}
//this code will open a new screen which is (incomingCallpage.class) code for incomingCallpage

public class IncomingCallPage extends Activity {
    IncomingCallReceiver incomingCallReceiver;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Toast.makeText(IncomingCallPage.this, "Incoming call Page", 5000)
            .show();
    new AlertDialog.Builder(this)
            .setTitle("Incoming Call")
            .setMessage("From:242424")
            .setIcon(R.drawable.phone)
            .setPositiveButton("Accept",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {

                            **incomingCallReceiver.acceptCall();**
                        }
                    })
            .setNegativeButton("Reject",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            **incomingCallReceiver.rejectCaLL();**
                        }
                    }).show();
}

}


//i have registered the reciever in manifest.xml file.

<uses-sdk android:minSdkVersion="9" />

<uses-feature
    android:name="android.hardware.sip.voip"
    android:required="true" />

<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-feature
    android:name="android.hardware.wifi"
    android:required="true" />
<uses-feature
    android:name="android.hardware.microphone"
    android:required="true" />

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

<application
    android:debuggable="true"
    android:icon="@drawable/logo_linphone_57x57"
    android:label="SIP Dialer" >
    <activity
        android:name=".WalkieTalkieActivity"
        android:configChanges="orientation|keyboardHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".SipSettings"
        android:label="set_preferences" />
    <activity
        android:name=".dialer"
        android:label="@string/app_name" />
    <activity
        android:name=".timer"
        android:label="@string/app_name" />
    <activity
        android:name=".d1"
        android:label="@string/app_name" />
    <activity
        android:name=".IncomingCallPage"
        android:label="@string/app_name" />

    **<receiver
        android:name=".IncomingCallReceiver"
        android:enabled="true"
        android:label="Call Receiver" >
        <intent-filter>
            <action android:name="android.SipDemo.INCOMING_CALL" />
        </intent-filter>
    </receiver>**
</application>

while running this code the error is :03-19 06:54:00.137: E/AndroidRuntime(1699):at com.example.android.sip.IncomingCallPage$1.onClick(IncomingCallPage.java:30)

回答1:

did you created instance?

incomingCallReceiver=new IncomingCallReceiver();

or change you method to static

public static void acceptCall() 

//and call this in your IncomingCallPage

IncomingCallReceiver.acceptCall()


标签: android sip