gpt4 book ai didi

android - 电话管理器 gsm 参数

转载 作者:行者123 更新时间:2023-11-30 02:44:01 24 4
gpt4 key购买 nike

我想知道电话管理器在Android平台上可以测量多少个GSM参数?代码示例将不胜感激。

最佳答案

首先,您应该查看官方文档http://developer.android.com/reference/android/telephony/PhoneStateListener.html

可供开发者使用的 GSM 参数并不多,比如国家代码、rssi,但没有带下划线的参数。

private void getNWInfo(Context context) {
/**
* <uses-permission android:name="android.permission.READ_PHONE_STATE"
* /> <uses-permission
* android:name="android.permission.ACCESS_NETWORK_STATE"/>
*/

TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = telephonyManager.getNetworkOperator();
int mcc = 0, mnc = 0;
if (networkOperator != null) {
mcc = Integer.parseInt(networkOperator.substring(0, 3));
mnc = Integer.parseInt(networkOperator.substring(3));
}

String SimNumber = telephonyManager.getLine1Number();

String SimSerialNumber = telephonyManager.getSimSerialNumber();
String countryISO = telephonyManager.getSimCountryIso();
String operatorName = telephonyManager.getSimOperatorName();
String operator = telephonyManager.getSimOperator();
int simState = telephonyManager.getSimState();

String voicemailNumer = telephonyManager.getVoiceMailNumber();
String voicemailAlphaTag = telephonyManager.getVoiceMailAlphaTag();

// Getting connected network iso country code
String networkCountry = telephonyManager.getNetworkCountryIso();
// Getting the connected network operator ID
String networkOperatorId = telephonyManager.getNetworkOperator();
// Getting the connected network operator name
String networkName = telephonyManager.getNetworkOperatorName();

int networkType = telephonyManager.getNetworkType();

String network = "";
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
if (cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
network = "Cell Network/3G";
else if (cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
network = "WiFi";
else
network = "N/A";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("network :" + network +

"\n" + "countryISO : " + countryISO + "\n" + "operatorName : "
+ operatorName + "\n" + "operator : " + operator + "\n"
+ "simState :" + simState + "\n" + "Sim Serial Number : "
+ SimSerialNumber + "\n" + "Sim Number : " + SimNumber + "\n"
+ "Voice Mail Numer" + voicemailNumer + "\n"
+ "Voice Mail Alpha Tag" + voicemailAlphaTag + "\n"
+ "Sim State" + simState + "\n" + "Mobile Country Code MCC : "
+ mcc + "\n" + "Mobile Network Code MNC : " + mnc + "\n"
+ "Network Country : " + networkCountry + "\n"
+ "Network OperatorId : " + networkOperatorId + "\n"
+ "Network Name : " + networkName + "\n" + "Network Type : "
+ networkType);

寻找更多信息here

关于android - 电话管理器 gsm 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25348710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com