我正在创建sip应用程序。我在我的micromax a26上测试它,它有android 2.3.5,我有问题
- →1
当我执行此代码时
if(SipManager.isApiSupported(getApplicationContext()))
Toast.makeText(getApplicationContext(), "support", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "not support", Toast.LENGTH_SHORT).show();
我得到“不支持”警报。
在这个http://developer.android.com/guide/topics/connectivity/sip.html中我说我需要你必须拥有一台运行Android 2.3或更高版本的移动设备。
我错过了什么?
- →2
在这一行
if(manager == null) {
manager = SipManager.newInstance(this);
}
if (manager == null) {
Toast.makeText(getApplicationContext(), "manager null", Toast.LENGTH_SHORT).show();
return;
}
我再次收到警报“经理null”所以我猜测SipManager.newInstance(this)重新调整null。请参阅此http://developer.android.com/reference/android/net/sip/SipManager.html#newInstance%28android.content.Context%29
这是我的整个代码
package com.archish;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.*;
import android.net.sip.*;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import java.text.ParseException;
public class SipTestActivity extends Activity implements View.OnTouchListener{
public String sipAddress;
public static SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call =null;
//public IncomingCallReceiver callReceiver;
EditText Domain;
EditText UId;
EditText Pwd;
private static final int CALL_ADDRESS = 1;
private static final int SET_AUTH_INFO = 2;
private static final int UPDATE_SETTINGS_DIALOG = 3;
private static final int HANG_UP = 4;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Domain=(EditText)findViewById(R.id.edtDomain);
UId=(EditText)findViewById(R.id.edtUid);
Pwd=(EditText)findViewById(R.id.edtPwd);
if(SipManager.isApiSupported(getApplicationContext()))
Toast.makeText(getApplicationContext(), "support", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "not support", Toast.LENGTH_SHORT).show();
IntentFilter filter = new IntentFilter();
filter.addAction("com.archish.INCOMING_CALL");
initializeManager();
/*Button Reg=(Button)findViewById(R.id.btnReg);
Reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "on click ", Toast.LENGTH_SHORT).show();
try {
Register();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});*/
}
private void initializeManager() {
if(manager == null) {
manager = SipManager.newInstance(getBaseContext());
}
Register();
}
public void Register()
{
if (manager == null) {
Toast.makeText(getApplicationContext(), "manager null", Toast.LENGTH_SHORT).show();
return;
}
if (me != null) {
closeLocalProfile();
}
try{
SipProfile.Builder builder = new SipProfile.Builder("1001", "123");
builder.setPassword("1234");
me = builder.build();
Intent i = new Intent();
i.setAction("com.archish.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
manager.open(me, pi, null);
// This listener must be added AFTER manager.open is called,
// Otherwise the methods aren't guaranteed to fire.
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
Toast.makeText(getApplicationContext(), "Registering with SIP Server...", Toast.LENGTH_SHORT).show();
// updateStatus("Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Toast.makeText(getApplicationContext(), "reaDy", Toast.LENGTH_SHORT).show();
// updateStatus("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
Toast.makeText(getApplicationContext(), "Registration failed. Please check settings.", Toast.LENGTH_SHORT).show();
// updateStatus("Registration failed. Please check settings.");
}
});
}
catch (ParseException pe) {
//updateStatus("Connection Error.");
} catch (SipException se) {
//updateStatus("Connection error.");
}
}
private void closeLocalProfile() {
if (manager == null) {
return;
}
try {
if (me != null) {
manager.close(me.getUriString());
}
} catch (Exception ee) {
Log.d("WalkieTalkieActivity/onDestroy", "Failed to close local profile.", ee);
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
}
请帮帮我!!!我是android的新手,给我任何提示来解决这个问题......问题是什么????