本帖最后由 咬字分开念 于 2023-10-3 20:30 编辑
好巧不巧我刚刚就写了一个手机标识符获取的java代码的apk,已经上架了,下面是关键代码
[Java] 纯文本查看 复制代码
package org.util;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
public class phoneinfo extends Activity {
public static String imei = "";
public static String imei2 = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
/*
* 电话状态:
* 1.tm.CALL_STATE_IDLE=0 无活动
* 2.tm.CALL_STATE_RINGING=1 响铃
* 3.tm.CALL_STATE_OFFHOOK=2 摘机
*/
// tm.getCallState();//int
/*
* 电话方位:
*
*/
// tm.getCellLocation();//CellLocation
/*
* 唯一的设备 ID:
* GSM 手机的 IMEI 和 CDMA 手机的 MEID.
* Return null if device ID is not available.
*/
imei = tm.getDeviceId();//String
}
public static String getIMEI() {
return imei;
}
public static String getIMEI(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}
public static String getIMEI2(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(imei2.isEmpty()){
imei2 = telephonyManager.getDeviceId();
}
return imei2;
}
}
/**
* 系统工具类
* Created by 程龙 on 2018-09-12.
*/
/**
*
*/
/**
public class phoneinfo {
/**
* 获取当前手机系统语言。
*
* [url=home.php?mod=space&uid=155549]@Return[/url] 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN”
public static String getSystemLanguage() {
return Locale.getDefault().getLanguage();
}
/**
* 获取当前系统上的语言列表(Locale列表)
*
* @return 语言列表
public static Locale[] getSystemLanguageList() {
return Locale.getAvailableLocales();
}
/**
* 获取当前手机系统版本号
*
* @return 系统版本号
public static String getSystemVersion() {
return android.os.Build.VERSION.RELEASE;
}
/**
* 获取手机型号
*
* @return 手机型号
public static String getSystemModel() {
return android.os.Build.MODEL;
}
/**
* 获取手机厂商
*
* @return 手机厂商
public static String getDeviceBrand() {
return android.os.Build.BRAND;
}
/**
* 获取手机IMEI(需要“android.permission.READ_PHONE_STATE”权限)
*
* @return 手机IMEI
public static String getIMEI() {
Application application = null;
Class<?> activityThreadClass;
try {
activityThreadClass = Class.forName("android.app.ActivityThread");
final Method method2 = activityThreadClass.getMethod(
"currentActivityThread", new Class[0]);
// 得到当前的ActivityThread对象
Object localObject = method2.invoke(null, (Object[]) null);
final Method method = activityThreadClass
.getMethod("getApplication");
application = (Application) method.invoke(localObject, (Object[]) null);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
TelephonyManager tm = (TelephonyManager) application.getSystemService(Activity.TELEPHONY_SERVICE);
if (tm != null) {
return tm.getDeviceId();
}
}catch ( Exception ee){
Logger.info("imeierr:"+ee.toString());
}
return null;
}
public static String imei() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return "";
}
}
*/
|