本文整理了Java中android.telephony.TelephonyManager.isNetworkRoaming()
方法的一些代码示例,展示了TelephonyManager.isNetworkRoaming()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.isNetworkRoaming()
方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:isNetworkRoaming
暂无
代码示例来源:origin: stackoverflow.com
ConnectivityManager mConnectivity = null;
TelephonyManager mTelephony = null;
// Skip if no connection, or background data disabled
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null || !mConnectivity.getBackgroundDataSetting()) {
return false;
}
// Only update if WiFi or 3G is connected and not roaming
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
} else if (netType == ConnectivityManager.TYPE_MOBILE
&& netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
&& !mTelephony.isNetworkRoaming()) {
return info.isConnected();
} else {
return false;
}
代码示例来源:origin: square/assertj-android
public TelephonyManagerAssert isNetworkRoaming() {
isNotNull();
assertThat(actual.isNetworkRoaming()) //
.overridingErrorMessage("Expected the device to be considered roaming but was not.") //
.isTrue();
return this;
}
代码示例来源:origin: square/assertj-android
public TelephonyManagerAssert isNotNetworkRoaming() {
isNotNull();
assertThat(actual.isNetworkRoaming()) //
.overridingErrorMessage("Expected the device to not be considered roaming but was.") //
.isFalse();
return this;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSetIsNetworkRoaming() {
shadowOf(telephonyManager).setIsNetworkRoaming(true);
assertTrue(telephonyManager.isNetworkRoaming());
}
代码示例来源:origin: stackoverflow.com
public class RoamingListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.isNetworkRoaming())
Toast.makeText(context, "Is on TelephonyM Roaming", Toast.LENGTH_LONG).show();
}
}
代码示例来源:origin: stackoverflow.com
public class RoamingListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.isNetworkRoaming())
Toast.makeText(context, "Is on TelephonyM Roaming", Toast.LENGTH_LONG).show();
}
}
代码示例来源:origin: gdpancheng/LoonAndroid3
/**
* 手机是否处在漫游
*
* @param mCm
* @return boolean
*/
public boolean isNetworkRoaming(Context mCm) {
ConnectivityManager connectivity = (ConnectivityManager) mCm.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
}
NetworkInfo info = connectivity.getActiveNetworkInfo();
boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
TelephonyManager mTm = (TelephonyManager) mCm.getSystemService(Context.TELEPHONY_SERVICE);
boolean isRoaming = isMobile && mTm.isNetworkRoaming();
return isRoaming;
}
代码示例来源:origin: xiangzhihong/zhihu
public boolean isNetworkRoaming(Context context) {
if (conManager != null) {
NetworkInfo info = conManager.getActiveNetworkInfo();
if (info != null
&& info.getType() == ConnectivityManager.TYPE_MOBILE) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null && tm.isNetworkRoaming()) {
Log.d("Tag", "network is roaming");
return true;
} else {
Log.d("Tag", "network is not roaming");
}
}
}
return false;
}
代码示例来源:origin: Over17/UnityOBBDownloader
public boolean isNetworkRoaming() {
ConnectivityManager connectivity =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
Log.w(Constants.TAG, "couldn't get connectivity manager");
return false;
}
NetworkInfo info = connectivity.getActiveNetworkInfo();
boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
TelephonyManager tm = (TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE);
if (null == tm) {
Log.w(Constants.TAG, "couldn't get telephony manager");
return false;
}
boolean isRoaming = isMobile && tm.isNetworkRoaming();
if (Constants.LOGVV && isRoaming) {
Log.v(Constants.TAG, "network is roaming");
}
return isRoaming;
}
代码示例来源:origin: gdpancheng/LoonAndroid3
/**
* 检测手机是否开启GPRS网络,需要调用ConnectivityManager,TelephonyManager 服务.
*
* @param context
* @return boolean
*/
public static boolean checkGprsNetwork(Context context) {
boolean has = false;
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
NetworkInfo info = connectivity.getActiveNetworkInfo();
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) {
has = info.isConnected();
}
return has;
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public TelephonyManagerAssert isNotNetworkRoaming() {
isNotNull();
assertThat(actual.isNetworkRoaming()) //
.overridingErrorMessage("Expected the device to not be considered roaming but was.") //
.isFalse();
return this;
}
代码示例来源:origin: stackoverflow.com
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onServiceStateChanged(ServiceState serviceState) {
super.onServiceStateChanged(serviceState);
if (telephonyManager.isNetworkRoaming()) {
// In Roaming
} else {
// Not in Roaming
}
// You can also check roaming state using this
if (serviceState.getRoaming()) {
// In Roaming
} else {
// Not in Roaming
}
}
};
代码示例来源:origin: com.squareup.assertj/assertj-android
public TelephonyManagerAssert isNetworkRoaming() {
isNotNull();
assertThat(actual.isNetworkRoaming()) //
.overridingErrorMessage("Expected the device to be considered roaming but was not.") //
.isTrue();
return this;
}
代码示例来源:origin: Lovemma/ZhihuDaily
&& !telephonyManager.isNetworkRoaming()) {
netType = 4;
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
|| nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
|| nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming()) {
netType = 3;
|| nSubType == TelephonyManager.NETWORK_TYPE_EDGE
|| nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming()) {
netType = 2;
} else {
代码示例来源:origin: FussenYu/MVP_Project
&& !telephonyManager.isNetworkRoaming()) {
netType = 4;
} else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
|| nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
|| nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
&& !telephonyManager.isNetworkRoaming()) {
netType = 3;
|| nSubType == TelephonyManager.NETWORK_TYPE_EDGE
|| nSubType == TelephonyManager.NETWORK_TYPE_CDMA
&& !telephonyManager.isNetworkRoaming()) {
netType = 2;
} else {
代码示例来源:origin: stackoverflow.com
ConnectivityManager mConnectivity = null;
TelephonyManager mTelephony = null;
// Skip if no connection, or background data disabled
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null || !mConnectivity.getBackgroundDataSetting()) {
return false;
}
// Only update if WiFi or 3G is connected and not roaming
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
} else if (netType == ConnectivityManager.TYPE_MOBILE
&& netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
&& !mTelephony.isNetworkRoaming()) {
return info.isConnected();
} else {
return false;
}
代码示例来源:origin: denzilferreira/aware-client
complianceStatus.put("roaming", telephonyManager.isNetworkRoaming());
complianceStatus.put("location_gps", locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
complianceStatus.put("location_network", locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
代码示例来源:origin: stackoverflow.com
int typeOfConnection = 0;
//Gets the system service of the connectivity.
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = connectivityManager.getAllNetworkInfo();
//Checks whether the connectivity type is WIFI or MOBILE.
for (NetworkInfo networkInfo : netInfo)
{
if (networkInfo.getTypeName().equalsIgnoreCase("WIFI"))
if (networkInfo.isConnected()){
typeOfConnection = 1;
Toast.makeText(getApplicationContext(), "net on", Toast.LENGTH_LONG).show();
}
if (networkInfo.getTypeName().equalsIgnoreCase("MOBILE"))
if (networkInfo.isConnected()){
typeOfConnection = 2;
Toast.makeText(getApplicationContext(), "net on", Toast.LENGTH_LONG).show();
}
}
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(typeOfConnection== 2 && telephonyManager.isNetworkRoaming()){
typeOfConnection = 3;
}
if(typeOfConnection == 0){
Toast.makeText(getApplicationContext(), "net OFF", Toast.LENGTH_LONG).show();
}
代码示例来源:origin: klinker41/android-smsmms
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
roaming = telephony.isNetworkRoaming();
if (state.subscriberId != null) {
subscriberId = state.subscriberId;
代码示例来源:origin: openbmap/radiocells-scanner-android
Log.i(TAG, "Network operator: " + mTelephonyManager.getNetworkOperator());
Log.i(TAG, mTelephonyManager.getNetworkOperatorName());
Log.i(TAG, "Roaming: " + mTelephonyManager.isNetworkRoaming());
Log.wtf(TAG, "------------ YOU MAY WANT TO REDACT INFO BELOW ABOVE POSTING THIS TO THE INTERNET ------------ ");
内容来源于网络,如有侵权,请联系作者删除!