頭條API上報(bào)痊夭,上報(bào)接口執(zhí)行一遍,聯(lián)調(diào)那會(huì)有兩遍數(shù)據(jù)塞颁,頭條的問題过咬,暫無法解決大渤;
上報(bào)的時(shí)候遇到的坑:
1.上報(bào)需要imei android,oaid
a. imei :android10以上獲取不到:
b, androidID 和頭條的比對(duì)不上,(下面是我使用的方法援奢,有知道原因的請(qǐng)告訴我)
c.oaid需要使用msa_mdid_1.0.13這版本的aar(有需要這版本的可以聯(lián)系我)
(移動(dòng)開發(fā)聯(lián)盟)
使用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", "獲取返回設(shè)備id 成功:"+ tm.getDeviceId());
}
}
} catch (Exception e) {
}
return deviceId;
}
public class SystemUtil {
public static String getPacakcageModel() {
return "ocrtwo";
}
/**
* 獲取版本號(hào)
*
* @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";
}
/**
* 獲取版本號(hào)
*
* @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;
}
/**
* 獲取手機(jī)廠商
*
* @return 手機(jī)廠商
*/
public static String getDeviceBrand() {
return Build.BRAND;
}
/**
* 獲取手機(jī)型號(hào)
*
* @return 手機(jī)型號(hào)
*/
public static String getSystemModel() {
return Build.MODEL;
}
/**
* 系統(tǒng)版本
* @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", "獲取返回設(shè)備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號(hào)
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception exception) {
//serial需要一個(gè)初始化
serial = "serial"; // 隨便一個(gè)初始化
}
//使用硬件信息拼湊出來的15位號(hào)碼
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以下手機(jī)直接獲取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 {
//獲取本機(jī)器所有的網(wǎng)絡(luò)接口
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) {
//格式化為:兩位十六進(jìn)制加冒號(hào)的格式集漾,若是不足兩位,補(bǔ)0
stringBuilder.append(String.format("%02X:", new Object[] { Byte.valueOf(b) }));
}
if (stringBuilder.length() > 0) {
//刪除后面多余的冒號(hào)
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
String str = stringBuilder.toString();
// wlan0:無線網(wǎng)卡 eth0:以太網(wǎng)卡
if (networkInterface.getName().equals("wlan0")) {
return str;
}
}
} catch (SocketException socketException) {
return null;
}
return null;
}
}