我们在使用短视频app源码时,都需要先进行注册才能使用源码内的全部功能,其中手机号注册以及短信验证是最常使用的方式,那么在短视频app源码开发时,要如何做才能获取到SIM卡信息和手机号码呢?
以下是实现代码:
import android.content.Context;
import android.telephony.TelephonyManager;
/**
* Created by WangJinyong on 2018/3/31.
* 获取SIM卡信息和手机号码
*/
public class PhoneInfoUtils {
private static String TAG = "PhoneInfoUtils";
private TelephonyManager telephonyManager;
//移动运营商编号
private String NetworkOperator;
private Context context;
public PhoneInfoUtils(Context context) {
this.context = context;
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}
//获取sim卡iccid
public String getIccid() {
String iccid = "N/A";
iccid = telephonyManager.getSimSerialNumber();
return iccid;
}
//获取电话号码
public String getNativePhoneNumber() {
String nativePhoneNumber = "N/A";
nativePhoneNumber = telephonyManager.getLine1Number();
return nativePhoneNumber;
}
//获取手机服务商信息
public String getProvidersName() {
String providersName = "N/A";
NetworkOperator = telephonyManager.getNetworkOperator();
//IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
// Flog.d(TAG,"NetworkOperator=" + NetworkOperator);
if (NetworkOperator.equals("46000") || NetworkOperator.equals("46002")) {
providersName = "中国移动";//中国移动
} else if (NetworkOperator.equals("46001")) {
providersName = "中国联通";//中国联通
} else if (NetworkOperator.equals("46003")) {
providersName = "中国电信";//中国电信
}
return providersName;
}
public String getPhoneInfo() {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
StringBuffer sb = new StringBuffer();
sb.append("\nLine1Number = " + tm.getLine1Number());
sb.append("\nNetworkOperator = " + tm.getNetworkOperator());//移动运营商编号
sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());//移动运营商名称
sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
sb.append("\nSimOperator = " + tm.getSimOperator());
sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
return sb.toString();
}
}
以上就是短视频app源码开发,Android端获取SIM卡信息和手机号码的全部内容了,希望对大家能有多帮助。