本文整理汇总了Java中android.telephony.TelephonyManager类的典型用法代码示例。如果您正苦于以下问题:Java TelephonyManager类的具体用法?Java TelephonyManager怎么用?Java TelephonyManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TelephonyManager类属于android.telephony包,在下文中一共展示了TelephonyManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImei
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* get the current version of current application
*/
public static String getImei( Context context) {
if (TextUtils.isEmpty(imei)) {
if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){
TelephonyManager tm = (TelephonyManager) context.getApplicationContext()
.getSystemService(Context.TELEPHONY_SERVICE);
imei = tm.getDeviceId();
}
}
return imei;
}
示例2: getDefaultVoiceSubscriptionSimSlot
import android.telephony.TelephonyManager; //导入依赖的package包/类
private int getDefaultVoiceSubscriptionSimSlot() {
try {
final TelecomManager telecomManager =
(TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
final TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager,
"getUserSelectedOutgoingPhoneAccount");
if (pah != null) {
PhoneAccount pa = telecomManager.getPhoneAccount(pah);
int subId = getSubIdForPhoneAccount(telephonyManager, pa);
SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId);
if (si != null) {
return si.getSimSlotIndex();
}
}
return -1;
} catch (Throwable t) {
XposedBridge.log(t);
return -1;
}
}
示例3: getSimOperatorByMnc
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* 获取Sim卡运营商名称
* <p>中国移动、如中国联通、中国电信</p>
*
* @return 移动网络运营商名称
*/
public static String getSimOperatorByMnc() {
TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
String operator = tm != null ? tm.getSimOperator() : null;
if (operator == null) return null;
switch (operator) {
case "46000":
case "46002":
case "46007":
return "中国移动";
case "46001":
return "中国联通";
case "46003":
return "中国电信";
default:
return operator;
}
}
示例4: onCreate
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* Creates the activity, sets the view, and checks if Telephony is enabled.
* Telephony enabled:
* Checks for phone permission.
* Sets the PhoneStateListener.
* Telephony not enabled: Disables the call button and shows the Retry button.
*
* @param savedInstanceState Instance state
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a telephony manager.
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// Check to see if Telephony is enabled.
if (isTelephonyEnabled()) {
Log.d(TAG, getString(R.string.telephony_enabled));
// Check for phone permission.
checkForPhonePermission();
// Register the PhoneStateListener to monitor phone activity.
mListener = new MyPhoneCallListener();
mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
} else {
Toast.makeText(this,
R.string.telephony_not_enabled, Toast.LENGTH_LONG).show();
Log.d(TAG, getString(R.string.telephony_not_enabled));
// Disable the call button.
disableCallButton();
}
}
示例5: isWifiEnabled
import android.telephony.TelephonyManager; //导入依赖的package包/类
public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService
("connectivity");
return (mgrConn.getActiveNetworkInfo() != null && mgrConn.getActiveNetworkInfo().getState
() == State.CONNECTED) || ((TelephonyManager) context.getSystemService("phone"))
.getNetworkType() == 3;
}
示例6: getNetworkClass
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* 获取在Mobile网络下的网络类型. 2G,3G,4G
*
* @param context
* @return
*/
public static int getNetworkClass(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null) {
if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
return NETWORK_CLASS_2_G;
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B:
case 14: // TelephonyManager.NETWORK_TYPE_EHRPD:
case 15: // TelephonyManager.NETWORK_TYPE_HSPAP:
return NETWORK_CLASS_3_G;
case 13: // TelephonyManager.NETWORK_TYPE_LTE:
return NETWORK_CLASS_4_G;
default:
return NETWORK_CLASS_UNKNOWN;
}
} else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return NETWORK_CLASS_WIFI;
}
}
}
return NETWORK_CLASS_UNKNOWN;
}
示例7: toJson
import android.telephony.TelephonyManager; //导入依赖的package包/类
String toJson(Context context) {
try {
appName = context.getString(R.string.app_name);
systemType = "Android";
systemVersion = Build.VERSION.RELEASE;
version = "1.0";
deviceModel = Build.MODEL;
deviceName = Build.PRODUCT;
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
appVersion = pi.versionName;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
operator = telephonyManager.getSimOperatorName();
connectionType = NetworkStauts.getCurrentNetworkType(context);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return new Gson().toJson(this);
}
示例8: getPhoneStatus
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* 获取手机状态信息
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return DeviceId(IMEI) = 99000311726612<br>
* DeviceSoftwareVersion = 00<br>
* Line1Number =<br>
* NetworkCountryIso = cn<br>
* NetworkOperator = 46003<br>
* NetworkOperatorName = 中国电信<br>
* NetworkType = 6<br>
* honeType = 2<br>
* SimCountryIso = cn<br>
* SimOperator = 46003<br>
* SimOperatorName = 中国电信<br>
* SimSerialNumber = 89860315045710604022<br>
* SimState = 5<br>
* SubscriberId(IMSI) = 460030419724900<br>
* VoiceMailNumber = *86<br>
*/
@SuppressLint("HardwareIds")
public static String getPhoneStatus(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String str = "";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
str += "Line1Number = " + tm.getLine1Number() + "\n";
str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "NetworkType = " + tm.getNetworkType() + "\n";
str += "PhoneType = " + tm.getPhoneType() + "\n";
str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "SimOperator = " + tm.getSimOperator() + "\n";
str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SimState = " + tm.getSimState() + "\n";
str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
return str;
}
示例9: b
import android.telephony.TelephonyManager; //导入依赖的package包/类
public static boolean b(Context context) {
if (!"CN".equalsIgnoreCase(((TelephonyManager) context.getSystemService("phone"))
.getSimCountryIso())) {
return false;
}
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService("connectivity");
if (connectivityManager == null) {
return false;
}
try {
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return false;
}
String extraInfo = activeNetworkInfo.getExtraInfo();
return (TextUtils.isEmpty(extraInfo) || extraInfo.length() < 3 || extraInfo
.contains("ctwap")) ? false : extraInfo.regionMatches(true, extraInfo
.length() - 3, "wap", 0, 3);
} catch (Exception e) {
return false;
}
} catch (Exception e2) {
return false;
}
}
示例10: onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallTrue
import android.telephony.TelephonyManager; //导入依赖的package包/类
@Test
public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallTrue() {
CallStateListener instance = getInstance(true, false, mockReactContext);
instance.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, "8675309");
//always set the return flags
verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//Should always fire the event back to Javascript
WritableMap expected = new MockWritableMap();
expected.putString("phonenumber", "8675309");
expected.putString("state", "CALL_STATE_OFFHOOK");
verify(mockEmitter).emit("callStatusUpdate", expected);
//should launch the app
verify(mockApplicationContext).startActivity(mockIntent);
}
示例11: getMtkTeleInfo
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* MTK Phone.
* <p>
* 获取 MTK 神机的双卡 IMSI、IMSI 信息
*/
public static TeleInfo getMtkTeleInfo(Context context) {
TeleInfo teleInfo = new TeleInfo();
try {
Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
Field fields1 = phone.getField("GEMINI_SIM_1");
fields1.setAccessible(true);
int simId_1 = (Integer) fields1.get(null);
Field fields2 = phone.getField("GEMINI_SIM_2");
fields2.setAccessible(true);
int simId_2 = (Integer) fields2.get(null);
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Method getSubscriberIdGemini = TelephonyManager.class.getDeclaredMethod("getSubscriberIdGemini", int.class);
String imsi_1 = (String) getSubscriberIdGemini.invoke(tm, simId_1);
String imsi_2 = (String) getSubscriberIdGemini.invoke(tm, simId_2);
teleInfo.imsi_1 = imsi_1;
teleInfo.imsi_2 = imsi_2;
Method getDeviceIdGemini = TelephonyManager.class.getDeclaredMethod("getDeviceIdGemini", int.class);
String imei_1 = (String) getDeviceIdGemini.invoke(tm, simId_1);
String imei_2 = (String) getDeviceIdGemini.invoke(tm, simId_2);
teleInfo.imei_1 = imei_1;
teleInfo.imei_2 = imei_2;
Method getPhoneTypeGemini = TelephonyManager.class.getDeclaredMethod("getPhoneTypeGemini", int.class);
int phoneType_1 = (Integer) getPhoneTypeGemini.invoke(tm, simId_1);
int phoneType_2 = (Integer) getPhoneTypeGemini.invoke(tm, simId_2);
teleInfo.phoneType_1 = phoneType_1;
teleInfo.phoneType_2 = phoneType_2;
} catch (Exception e) {
e.printStackTrace();
}
ViseLog.i("MTK: " + teleInfo);
return teleInfo;
}
示例12: getPhoneMes
import android.telephony.TelephonyManager; //导入依赖的package包/类
public static void getPhoneMes(Context context) {
try {
TelephonyManager mTm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String mtype = Build.MODEL; // 手机型号
String mtyb = Build.BRAND;//手机品牌
mdevicetype = mtyb + "-" + mtype;
String platform = Build.VERSION.RELEASE;//手机Android系统版本
String display = Build.DISPLAY;//手机系统名称
mplatform = "Android版本:" + platform + " 系统名称:" + display;
mdeviceId = mTm.getDeviceId();//手机设备IME
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: getProvidersName
import android.telephony.TelephonyManager; //导入依赖的package包/类
/**
* 获取手机服务商信息 <BR>
* 需要加入权限<uses-permission
* android:name="android.permission.READ_PHONE_STATE"/> <BR>
*/
public static String getProvidersName(Context context) {
String providersName = null;
// 返回唯一的用户ID;就是这张卡的编号神马的
String IMSI = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
if(IMSI != null){
// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
providersName = "中国移动";
} else if (IMSI.startsWith("46001")) {
providersName = "中国联通";
} else if (IMSI.startsWith("46003")) {
providersName = "中国电信";
}
} else {
providersName = null;
}
return providersName;
}
示例14: getDefaultSimInfo
import android.telephony.TelephonyManager; //导入依赖的package包/类
public static SimInfo getDefaultSimInfo(Context context) {
SimInfo simInfo = new SimInfo();
simInfo.setDeviceId(Device.getDeviceId(context));
simInfo.setDeviceModel(getDeviceModel());
TelephonyManager telMgr = (TelephonyManager) context.getSystemService("phone");
if (telMgr != null) {
simInfo.setIMSI(telMgr.getSubscriberId());
simInfo.setCCID(telMgr.getSimSerialNumber());
if (SimInfo.valid(simInfo)) {
return simInfo;
}
LOG.e(TAG, "get telephony manager ok but sim info invalid");
return null;
}
LOG.e(TAG, "get telephony manager failed while getting default sim info");
return null;
}
示例15: isNetworkRoaming
import android.telephony.TelephonyManager; //导入依赖的package包/类
@Override
public boolean isNetworkRoaming() {
ConnectivityManager connectivity =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
Log.w(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);
boolean isRoaming = isMobile && tm.isNetworkRoaming();
if (Constants.LOGVV && isRoaming) {
Log.v(TAG, "network is roaming");
}
return isRoaming;
}