SipDemo的onReceive()SipAudioCall NullPointerException给出

时间:2013-03-13 10:38:04

标签: android broadcastreceiver sip sip-server

我正在SipDemo创建来电接收活动。我的活动有两个按钮“接听电话”和“拒绝电话”。当我接到来电时,我自己的活动是开放的,例如  ---->来电类----> onReceive() ---->去我的电话挑选活动。 这是上面的两个按钮,如接受和拒绝呼叫。但是当我点击“接听电话”时。生成Nullpointer Exception。它是在SipAudiocall传入;

这是传入的类: -

static SipAudioCall incomingCall = null;
@Override
public void onReceive(final Context context, Intent intent) {

 Intent startActivity = new Intent(); 
     startActivity.setClass(context, Mycall.class); 
      startActivity.setAction(IncomingCallReceiver.class.getName()); 
      startActivity.setFlags( 
              Intent.FLAG_ACTIVITY_NEW_TASK 
              | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
      context.startActivity(startActivity);   


}

public static 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();
    }
}

这是我的电话挑选活动类: -

public class Mycall extends Activity {

Button acct;
 IncomingCallReceiver incomingCallReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
    // Note that none of the preferences are actually defined here.
    // They're all in the XML file res/xml/preferences.xml.
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my);

    acct = (Button) findViewById(R.id.button1);
    acct.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            IncomingCallReceiver.acceptCall();

        }
    });



}

}

这是AndroidManifest.xml: -

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.android.sip">
<application android:icon="@drawable/icon" android:label="SipDemo">
     <service android:name=".MService">

     </service>
  <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"/>


    <receiver android:name=".IncomingCallReceiver"   android:enabled="true" android:label="Call Receiver">
        <intent-filter>
       <action android:name="android.SipDemo.INCOMING_CALL" />
    </intent-filter>
      </receiver>
          <activity android:name=".Mycall"
               >
              </activity> 
           <activity android:name=".Myclass"/> 
</application>
<uses-sdk android:minSdkVersion="9" />
<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.READ_PHONE_STATE"/>

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

请专家帮助我。我从1个月开始涉及这个问题。

我等你的回复。

谢谢

1 个答案:

答案 0 :(得分:0)

想要你的

IncomingCallReceiver incomingCallReceiver;

在调用它时为空... 如果你创建一个静态类,你必须注意使用creator-method启动它。

创建一个抽象类:

public abstract class IncomingCallReceiver

并将您的方法更改为public static final