在服务类的onStartCommand
上调用了我的below方法,并且对于API级别27及更低版本而言,它可以正常工作。这样就可以成功发起SIP呼叫,而不会出现任何问题。
但是对于API级别28,sipManager无法打开,并且不会调用mSipManager.setRegistrationListener
。因此不会调用SIP onRegistering
,onRegistrationDone
或onRegistrationFailed
。找不到警告或错误。 API级别28应该怎么做?
public void initializeLocalProfile() {
try {
SipProfile.Builder builder = new SipProfile.Builder(sip_username, "" + sipServerDomain);
builder.setPort(sipPort);
builder.setPassword(sip_password);
mSipProfile = builder.build();
Intent i = new Intent();
i.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
mSipManager = SipManager.newInstance(this);
mSipManager.open(mSipProfile, pi, null);
if (mSipManager.isOpened(sip_username + "@" + sipServerDomain)) {
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
@Override
public void onRegistering(String localProfileUri) {
Log.d(TAG, "Registering with SIP Server..., localProfileUri2: " + localProfileUri);
}
@Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.d(TAG, "SIP onRegistrationDone, expiryTime: " + expiryTime);
((AeroApplication) getApplication()).setRegisteredSIP(true);
}
@Override
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
Log.d(TAG, "SIP Registration failed :" + errorMessage + ", errorCode :" + errorCode);
}
});
} else {
Toast.makeText(context, "SIP SipManager not opened, try again.", Toast.LENGTH_SHORT).show();
}
} catch (ParseException pe) {
Log.d(TAG, " SIP ParseException : " + pe.getMessage());
} catch (SipException se) {
Log.d(TAG, "SIP Exception: " + se.getMessage());
}
}