本文整理了Java中android.telephony.TelephonyManager.getPhoneType()
方法的一些代码示例,展示了TelephonyManager.getPhoneType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.getPhoneType()
方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:getPhoneType
暂无
代码示例来源:origin: stackoverflow.com
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
return "Tablet";
}else{
return "Mobile";
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
/**
* 获取移动终端类型
*
* @param context 上下文
* @return 手机制式
* <ul>
* <li>PHONE_TYPE_NONE : 0 手机制式未知</li>
* <li>PHONE_TYPE_GSM : 1 手机制式为GSM,移动和联通</li>
* <li>PHONE_TYPE_CDMA : 2 手机制式为CDMA,电信</li>
* <li>PHONE_TYPE_SIP : 3</li>
* </ul>
*/
public static int getPhoneType(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return tm != null ? tm.getPhoneType() : -1;
}
代码示例来源:origin: smuyyh/BookReader
/**
* 获取移动终端类型
*
* @param context 上下文
* @return 手机制式
* <ul>
* <li>{@link TelephonyManager#PHONE_TYPE_NONE } : 0 手机制式未知</li>
* <li>{@link TelephonyManager#PHONE_TYPE_GSM } : 1 手机制式为GSM,移动和联通</li>
* <li>{@link TelephonyManager#PHONE_TYPE_CDMA } : 2 手机制式为CDMA,电信</li>
* <li>{@link TelephonyManager#PHONE_TYPE_SIP } : 3</li>
* </ul>
*/
public static int getPhoneType(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return tm != null ? tm.getPhoneType() : -1;
}
代码示例来源:origin: stackoverflow.com
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
public static String getUserCountry(Context context) {
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
return simCountry.toLowerCase(Locale.US);
}
else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
String networkCountry = tm.getNetworkCountryIso();
if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
return networkCountry.toLowerCase(Locale.US);
}
}
}
catch (Exception e) { }
return null;
}
代码示例来源:origin: square/assertj-android
public TelephonyManagerAssert hasPhoneType(@TelephonyManagerPhoneType int type) {
isNotNull();
int actualType = actual.getPhoneType();
//noinspection ResourceType
assertThat(actualType) //
.overridingErrorMessage("Expected phone type <%s> but was <%s>.", phoneTypeToString(type),
phoneTypeToString(actualType)) //
.isEqualTo(type);
return this;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldGivePhoneType() {
shadowOf(telephonyManager).setPhoneType(TelephonyManager.PHONE_TYPE_CDMA);
assertEquals(TelephonyManager.PHONE_TYPE_CDMA, telephonyManager.getPhoneType());
shadowOf(telephonyManager).setPhoneType(TelephonyManager.PHONE_TYPE_GSM);
assertEquals(TelephonyManager.PHONE_TYPE_GSM, telephonyManager.getPhoneType());
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
// SHOW A DIALOG, A TOAST OR A NOTIFICATION TO TELL THE USER THAT THE FEATURE IS MISSING
} else {
// RUN THE CODE TO SEND OUT THE SMS
}
代码示例来源:origin: stackoverflow.com
final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
if (location != null) {
msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
}
}
代码示例来源:origin: DaxiaK/MyDiary
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.But_contacts_call_call:
TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
//No module for calling phone
Toast.makeText(getActivity(), getString(R.string.contacts_call_phone_no_call_function), Toast.LENGTH_LONG)
.show();
} else {
//Can call phone
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + contactsPhoneNumber));
startActivity(intent);
}
dismiss();
break;
case R.id.But_contacts_call_cancel:
dismiss();
break;
}
}
代码示例来源:origin: stackoverflow.com
TelephonyManager manager =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
{ // it has no phone
}
代码示例来源:origin: stackoverflow.com
private boolean hasPhoneAbility()
{
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
return false;
return true;
}
代码示例来源:origin: qyxxjd/BaseProject
/**
* 返回移动终端的类型
* <pre>
* 0:PHONE_TYPE_NONE 手机制式未知,可能是平板
* 1:PHONE_TYPE_GSM 手机制式为GSM,移动和联通
* 2:PHONE_TYPE_CDMA 手机制式为CDMA,电信
* </pre>
*/
public int getPhoneType() {
return mTelephonyManager.getPhoneType();
}
代码示例来源:origin: stackoverflow.com
TelephonyManager mManager_;
mManager_ = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if(mManager_.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA){
//CDMA PHONE
}
else if(mManager_.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM){
//GSM PHONE
}
uses permission: android.permission.ACCESS_NETWORK_STATE
代码示例来源:origin: stackoverflow.com
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
return "Tablet";
}else{
return "Mobile";
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm= (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
if(tm.getPhoneType()==TelephonyManager.PHONE_TYPE_NONE){
//No calling functionality
}
else
{
//calling functionality
}
代码示例来源:origin: yaozs/YzsLib
/**
* 判断设备是否是手机
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isPhone(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
代码示例来源:origin: stackoverflow.com
public static boolean isTablet(Context context) {
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE;
}
代码示例来源:origin: stackoverflow.com
try {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
return "";
return tm.getDeviceId();
} catch (Throwable e) {
return null;
}
代码示例来源:origin: geniusgithub/AndroidDialer
/**
* @return true if the phone is a CDMA phone type
*/
private boolean phoneIsCdma() {
return getTelephonyManager().getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public TelephonyManagerAssert hasPhoneType(@TelephonyManagerPhoneType int type) {
isNotNull();
int actualType = actual.getPhoneType();
//noinspection ResourceType
assertThat(actualType) //
.overridingErrorMessage("Expected phone type <%s> but was <%s>.", phoneTypeToString(type),
phoneTypeToString(actualType)) //
.isEqualTo(type);
return this;
}
内容来源于网络,如有侵权,请联系作者删除!