问题描述
我正在开发的传入和传出呼叫的SIP应用程序,我想显示的 AlertDialog 在来电。为此,我已经把两个按钮对话框接受和拒绝。在pressing这个按钮的应用程序中的任何一个是崩溃。
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.
这是我的类的code 和清单文件。
$ C $下incomingCallReciever
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();
}
}
}
//这个code将打开一个新的屏幕,这是(incomingCallpage.class)$ C $下incomingCallpage
}
//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();
}
}
//我已经登记在manifest.xml文件中reciever。
//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>
在运行C中的错误此$ C $是:六月3日至19日:54:00.137:E / AndroidRuntime(1699年):在com.example.android.sip.IncomingCallPage $ 1.onClick( IncomingCallPage.java:30)
推荐答案
你创建的实例?
incomingCallReceiver=new IncomingCallReceiver();
或者改变你的方法静态
or change you method to static
public static void acceptCall()
//并调用这在IncomingCallPage
//and call this in your IncomingCallPage
IncomingCallReceiver.acceptCall()
这篇关于应用程序崩溃,而使用不同类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!