|
alicloud-android-third-push-huawei-3.4.0.aar
就是实现了这样的注册逻辑的
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package com.alibaba.sdk.android.push.huawei;
- import android.app.Application;
- import android.content.Context;
- import android.content.pm.ApplicationInfo;
- import android.os.Build;
- import android.os.Handler;
- import android.os.Looper;
- import android.os.Build.VERSION;
- import android.text.TextUtils;
- import com.alibaba.sdk.android.push.impl.HuaweiMsgParseImpl;
- import com.alibaba.sdk.android.push.register.ThirdPushManager;
- import com.alibaba.sdk.android.push.register.ThirdPushManager.ThirdPushReportKeyword;
- import com.alibaba.sdk.android.push.utils.SysUtils;
- import com.alibaba.sdk.android.push.utils.ThreadUtil;
- import com.huawei.hms.aaid.HmsInstanceId;
- import com.taobao.accs.utl.ALog;
- public class HuaWeiRegister {
- private static final String TAG = "MPS:HuaWeiRegister";
- public static boolean isChannelRegister = false;
- public HuaWeiRegister() {
- }
- public static boolean register(Application application) {
- return registerBundle(application, false);
- }
- public static boolean registerBundle(final Application application, boolean channelRegister) {
- try {
- isChannelRegister = channelRegister;
- if (!isChannelRegister && !SysUtils.isMainProcess(application)) {
- ALog.e("MPS:HuaWeiRegister", "register not in main process, return", new Object[0]);
- return false;
- }
- if (checkDevice() && VERSION.SDK_INT >= 17) {
- ThirdPushManager.registerImpl(new HuaweiMsgParseImpl());
- Handler handler = new Handler(Looper.getMainLooper());
- handler.postDelayed(new Runnable() {
- public void run() {
- ALog.i("MPS:HuaWeiRegister", "register begin isChannel:" + HuaWeiRegister.isChannelRegister, new Object[0]);
- HuaWeiRegister.getToken(application.getApplicationContext());
- }
- }, 5000L);
- return true;
- }
- ALog.i("MPS:HuaWeiRegister", "register checkDevice false", new Object[0]);
- } catch (Throwable var3) {
- ALog.e("MPS:HuaWeiRegister", "register", var3, new Object[0]);
- }
- return false;
- }
- private static void getToken(final Context context) {
- ThreadUtil.getExecutor().execute(new Runnable() {
- public void run() {
- try {
- ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128);
- String value = appInfo.metaData.getString("com.huawei.hms.client.appid");
- String appId = "";
- if (!TextUtils.isEmpty(value)) {
- appId = value.replace("appid=", "");
- }
- ALog.i("MPS:HuaWeiRegister", "onToken", new Object[]{"appId", appId});
- String token;
- if (TextUtils.isEmpty(appId)) {
- token = HmsInstanceId.getInstance(context).getToken();
- } else {
- token = HmsInstanceId.getInstance(context).getToken(appId, "HCM");
- }
- if (!TextUtils.isEmpty(token)) {
- ALog.i("MPS:HuaWeiRegister", "onToken", new Object[]{"token", token});
- try {
- ThirdPushManager.reportToken(context, ThirdPushReportKeyword.HUAWEI.thirdTokenKeyword, token);
- } catch (Exception var7) {
- var7.printStackTrace();
- }
- }
- } catch (Exception var8) {
- ALog.e("MPS:HuaWeiRegister", "getToken failed.", var8, new Object[0]);
- try {
- ThirdPushManager.reportToken(context, ThirdPushReportKeyword.HUAWEI.thirdTokenKeyword, "");
- } catch (Exception var6) {
- var6.printStackTrace();
- }
- }
- }
- });
- }
- private static boolean checkDevice() {
- boolean result = false;
- if (Build.BRAND.equalsIgnoreCase("huawei") || Build.BRAND.equalsIgnoreCase("honor")) {
- result = true;
- }
- return result;
- }
- }
复制代码
|
|