我试图注册sip电话几天就遇到了问题。以下是我的代码,有人可以告诉我sip注册中的问题是什么吗?
public class SipRegistration extends Activity {
public String sipAddress;
public SipManager manager = null;
public SipProfile profile = null;
public SipAudioCall call = null;
private EditText user, pass, domaine;
// private SipAudioCall.Listener listener;
protected static final String TAG = null;
private Button register;
private SipRegistrationListener listener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
user = (EditText) findViewById(R.id.main_edtUser);
pass = (EditText) findViewById(R.id.main_edtPassword);
domaine = (EditText) findViewById(R.id.main_edtDomain);
register = (Button) findViewById(R.id.main_btnRegister);
register.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
initializeLocalProfile();
}
});
}
/**
* Logs you into your SIP provider, registering this device as the location
* to send SIP calls to for your SIP address.
*
* @return
*/
public boolean initializeLocalProfile() {
if (manager == null) {
manager = SipManager.newInstance(this);
}
Log.e("On build profile.......", "");
String username = user.getText().toString();
String domain = domaine.getText().toString();
String password = pass.getText().toString();
if (username.length() == 0 || domain.length() == 0
|| password.length() == 0) {
return true;
}
Log.e("@@@@@@@@", "username \n" + username);
Log.e("@@@@@@@@@", "domain \n" + domain);
Log.e("@@@@@@@", "password \n" + password);
try {
SipProfile.Builder builder = new SipProfile.Builder(username,
domain);
builder.setPassword(password);
profile = builder.build();
Log.e("profile Password", "" + builder.build());
// Intent i = new Intent();
// i.setAction("android.SipDemo.INCOMING_CALL");
// PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,
// Intent.FILL_IN_DATA);
// manager.open(profile, pi, null);
manager.open(profile);
Log.e("Profile:", "" + profile);
// Log.e("Intent:", "" + pi);
// Log.e("Listner:", "" + listener);
listener = new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
// TODO Auto-generated method stub
updateStatus("Registering with SIP Server...");
Log.e("Registration Running..........", "");
try {
manager.register(profile, 3000, listener);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onRegistrationDone(String localProfileUri,
long expiryTime) {
// TODO Auto-generated method stub
updateStatus("Ready");
Log.e("Registration Done..........", "");
}
public void onRegistrationFailed(String localProfileUri,
int errorCode, String errorMessage) {
// TODO Auto-generated method stub
updateStatus("Registration failed. Please check settings.");
Log.e("Registration failed..........", "");
}
};
if (manager.isRegistered(profile.getUriString())) {
Log.e("SipManager is ready for calls", "");
return true;
} else
return false;
} catch (Exception ex) {
Log.e("---Error-- initializeProfile: " + ex.getMessage(), "");
return false;
}
}
// This listener must be added AFTER manager.open is called,
// Otherwise the methods aren't guaranteed to fire.
public void updateStatus(final String status) {
// Be a good citizen. Make sure UI changes fire on the UI thread.
this.runOnUiThread(new Runnable() {
public void run() {
TextView labelView = (TextView) findViewById(R.id.main_sipLabel);
labelView.setText(status);
Log.e("Registration Running..........", "");
}
});
}
}
答案 0 :(得分:2)
使用
将端口号更改为8891
Sipmanger.port();
在真实设备(2.3)或更高版本上啜饮演示实际运行。 确保在清单文件中添加权限。