头条API上报,上报接口执行一遍,联调那会有两遍数据,头条的问题,暂无法解决;
上报的时候遇到的坑:
1.上报需要imei android,oaid
a. imei :android10以上获取不到:
b, androidID 和头条的比对不上,(下面是我使用的方法,有知道原因的请告诉我)
c.oaid需要使用msa_mdid_1.0.13这版本的aar(有需要这版本的可以联系我)
(移动开发联盟)
使用oaid + imei +androidID
以下是获取的方法:
//获取imei
public static String getDeviceId() {
String deviceId = "";
try {
if (ContextCompat.checkSelfPermission(MyApplication.getContext(), Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
TelephonyManager tm = (TelephonyManager) MyApplication.getContext().getSystemService(TELEPHONY_SERVICE);
deviceId = tm.getDeviceId();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
deviceId = tm.getImei();
Log.e("aaaa", "获取返回设备id 成功:"+ tm.getDeviceId());
}
}
} catch (Exception e) {
}
return deviceId;
}
public class SystemUtil {
public static String getPacakcageModel() {
return "ocrtwo";
}
/**
* 获取版本号
*
* @param
* @return
*/
public static String getVersion() {
try {
PackageManager manager = MyApplication.getContext().getPackageManager();
PackageInfo info = manager.getPackageInfo(MyApplication.getContext().getPackageName(), 0);
return info.versionCode + "";
} catch (Exception e) {
e.printStackTrace();
}
return "0";
}
/**
* 获取版本号
*
* @param
* @return
*/
public static String getVersionName() {
try {
PackageManager manager = MyApplication.getContext().getPackageManager();
PackageInfo info = manager.getPackageInfo(MyApplication.getContext().getPackageName(), 0);
return info.versionName + "";
} catch (Exception e) {
e.printStackTrace();
}
return "1.0.0";
}
/**
* 获取包名
*
* @param
* @return
*/
public static String getPckName() {
return MyApplication.getContext().getPackageName();
}
/**
* 获取渠道
*
* @param
* @return
*/
public static String getChannel() {
try {
ApplicationInfo appInfo = MyApplication.getContext().getPackageManager()
.getApplicationInfo(MyApplication.getContext().getPackageName(),
PackageManager.GET_META_DATA);
if (null != appInfo.metaData) {
return appInfo.metaData.getString("UMENG_CHANNEL");
} else {
return null;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取手机厂商
*
* @return 手机厂商
*/
public static String getDeviceBrand() {
return Build.BRAND;
}
/**
* 获取手机型号
*
* @return 手机型号
*/
public static String getSystemModel() {
return Build.MODEL;
}
/**
* 系统版本
* @return
*/
public static String getSystemRelease() {
return Build.VERSION.RELEASE;
}
public static String getDeviceId() {
String deviceId = "";
try {
if (ContextCompat.checkSelfPermission(MyApplication.getContext(), Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
TelephonyManager tm = (TelephonyManager) MyApplication.getContext().getSystemService(TELEPHONY_SERVICE);
deviceId = tm.getDeviceId();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
deviceId = tm.getImei();
Log.e("aaaa", "获取返回设备id 成功:"+ tm.getDeviceId());
}
}
} catch (Exception e) {
}
return deviceId;
}
public static String getMD5Imei(){
String deviceId = "";
if (!TextUtils.isEmpty(getDeviceId())) {
deviceId = MD5Utils.MD5_32bit(getDeviceId());
}
return deviceId;
}
public static String getMD5Android(Context context){
String deviceId = "";
if (!TextUtils.isEmpty(getAndroidId(context))) {
deviceId = MD5Utils.MD5_32bit(getAndroidId(context));
}
return deviceId;
}
public static String getUniquePsuedoID() {
String serial = null;
String m_szDevIDShort = "35" +
Build.BOARD.length() % 10 + Build.BRAND.length() % 10 +
Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 +
Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 +
Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 +
Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 +
Build.TAGS.length() % 10 + Build.TYPE.length() % 10 +
Build.USER.length() % 10; //13 位
try {
serial = Build.class.getField("SERIAL").get(null).toString();
//API>=9 使用serial号
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception exception) {
//serial需要一个初始化
serial = "serial"; // 随便一个初始化
}
//使用硬件信息拼凑出来的15位号码
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}
public static String getAndroidId (Context context) {
String ANDROID_ID = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
return ANDROID_ID;
}
/**
* 获取wifi的mac地址,适配到android Q
* @param paramContext
* @return
*/
public static String getMac(Context paramContext) {
try {
if (Build.VERSION.SDK_INT >= 23) {
String str = getMacMoreThanM(paramContext);
if (!TextUtils.isEmpty(str))
return str;
}
// 6.0以下手机直接获取wifi的mac地址即可
WifiManager wifiManager = (WifiManager)paramContext.getSystemService("WIFI");
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null)
return wifiInfo.getMacAddress();
} catch (Throwable throwable) {}
return null;
}
public static String getMacMd5(Context context){
String mac = getMac(context);
mac = mac.replaceAll(":","");
mac = mac.toUpperCase();
mac = MD5Utils.MD5_32bit(mac);
return mac;
}
/**
* android 6.0+获取wifi的mac地址
* @param paramContext
* @return
*/
private static String getMacMoreThanM(Context paramContext) {
try {
//获取本机器所有的网络接口
Enumeration enumeration = NetworkInterface.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
NetworkInterface networkInterface = (NetworkInterface)enumeration.nextElement();
//获取硬件地址,一般是MAC
byte[] arrayOfByte = networkInterface.getHardwareAddress();
if (arrayOfByte == null || arrayOfByte.length == 0) {
continue;
}
StringBuilder stringBuilder = new StringBuilder();
for (byte b : arrayOfByte) {
//格式化为:两位十六进制加冒号的格式,若是不足两位,补0
stringBuilder.append(String.format("%02X:", new Object[] { Byte.valueOf(b) }));
}
if (stringBuilder.length() > 0) {
//删除后面多余的冒号
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
String str = stringBuilder.toString();
// wlan0:无线网卡 eth0:以太网卡
if (networkInterface.getName().equals("wlan0")) {
return str;
}
}
} catch (SocketException socketException) {
return null;
}
return null;
}
}