gpt4 book ai didi

java - 如何以编程方式在android Q中获取IMSI?

转载 作者:行者123 更新时间:2023-12-02 02:40:54 26 4
gpt4 key购买 nike

TelephonyManager getSubscriberId()getSimSerialNumber() 在 android Q 中返回 null!

我正在使用 android studio IDE 进行 Java 编码!

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telephonyManager.getSimSerialNumber(); //it is null

最佳答案

如果您的apk的targetsdk <30,即使在android 11中,您也可以通过以下方法获取ICCID,无需任何权限。

    Uri uri = Uri.parse("content://telephony/siminfo");
Cursor cursor = null;
ContentResolver contentResolver = getApplicationContext().getContentResolver();
cursor = contentResolver.query(uri,
new String[]{"_id", "sim_id", "imsi","icc_id","number","display_name"}, "0=0",
new String[]{}, null);
if (null != cursor) {
while (cursor.moveToNext()) {
String icc_id = cursor.getString(cursor.getColumnIndex("icc_id"));
String imsi_id = cursor.getString(cursor.getColumnIndex("imsi"));
String phone_num = cursor.getString(cursor.getColumnIndex("number"));
String display_name = cursor.getString(cursor.getColumnIndex("display_name"));
int sim_id = cursor.getInt(cursor.getColumnIndex("sim_id"));
int _id = cursor.getInt(cursor.getColumnIndex("_id"));
Log.d("Q_M", "icc_id-->" + icc_id);
Log.d("Q_M", "imsi_id-->" + imsi_id);
Log.d("Q_M", "phone_num-->" + phone_num);
Log.d("Q_M", "sim_id-->" + sim_id);
Log.d("Q_M", "display_name-->" + display_name);
}
}

关于java - 如何以编程方式在android Q中获取IMSI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57180255/

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