说明
因为在移动网络下, 如果输入错误的网址, 会发生崩溃的情况, 所以极大的可能使用了WIFI, 就是在每次通话的时候都要检查是否网络可达.
Use WIFI only在每次检查的时候, 去检查配置文件.
这个是在.linphonerc配置文件中能够
// Network settings
public void setWifiOnlyEnabled(Boolean enable) {
getConfig().setBool("app", "wifi_only", enable);
}
public boolean isWifiOnlyEnabled() {
return getConfig().getBool("app", "wifi_only", false);
}
在LinphoneManager中使用
public void updateNetworkReachability() {
ConnectivityManager cm = (ConnectivityManager) mServiceContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected() || dozeModeEnabled) {
Log.i("No connectivity: setting network unreachable");
mLc.setNetworkReachable(false);
//mLc.setNetworkReachable(true);
} else if (networkInfo.isConnected()) {
manageTunnelServer(networkInfo);
boolean wifiOnly = LinphonePreferences.instance().isWifiOnlyEnabled();
if (wifiOnly) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI)
mLc.setNetworkReachable(true);
else {
Log.i("Wifi-only mode, setting network not reachable");
mLc.setNetworkReachable(false);
//mLc.setNetworkReachable(true);
}
} else {
int curtype = networkInfo.getType();
if (curtype != mLastNetworkType) {
//if kind of network has changed, we need to notify network_reachable(false) to make sure all current connections are destroyed.
//they will be re-created during setNetworkReachable(true).
Log.i("Connectivity has changed.");
mLc.setNetworkReachable(false);
//mLc.setNetworkReachable(true);
}
mLc.setNetworkReachable(true);
mLastNetworkType = curtype;
}
}
if (mLc.isNetworkReachable()) {
// When network isn't available, push informations might not be set. This should fix the issue.
LinphonePreferences prefs = LinphonePreferences.instance();
prefs.setPushNotificationEnabled(prefs.isPushNotificationEnabled());
}
}