应用程序在使用不同类的方法时崩溃

时间:2012-03-19 07:55:40

标签: android sip

我正在为来电和去电开发一个SIP应用程序,我想在来电上显示 AlertDialog 。为此,我放了两个带有对话框接受拒绝的按钮。按下其中一个按钮应用程序崩溃。

这是我的清单文件的代码。


来自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();
    }
}

}
//这段代码会打开一个新的屏幕,即(incomingCallpage.class) 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();
}

}


//我在manifest.xml文件中注册了接收器。

<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 个答案:

答案 0 :(得分:1)

你创建了实例吗?

incomingCallReceiver=new IncomingCallReceiver();

或将您的方法更改为静态

public static void acceptCall() 

//并在IncomingCallPage中调用它

IncomingCallReceiver.acceptCall()