xiongzhu 2 ani în urmă
părinte
comite
b084deb3c5
2 a modificat fișierele cu 42 adăugiri și 21 ștergeri
  1. 36 19
      src/android/UmengPlugin.java
  2. 6 2
      umeng.gradle

+ 36 - 19
src/android/UmengPlugin.java

@@ -1,5 +1,6 @@
 package com.umeng;
 
+import android.app.Application;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
@@ -32,6 +33,7 @@ import com.umeng.umverify.model.UMTokenRet;
 import com.umeng.umverify.view.UMAuthRegisterViewConfig;
 import com.umeng.umverify.view.UMAuthUIConfig;
 
+import org.android.agoo.huawei.HuaWeiRegister;
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaInterface;
 import org.apache.cordova.CordovaPlugin;
@@ -51,14 +53,15 @@ import vip.raex.nft.R;
 public class UmengPlugin extends CordovaPlugin {
 
     private final static String TAG = "CordovUmengPlugin";
-    private final static String umengKey = "62b5753a05844627b5c56bc8";
-    private final static String umengSecret = "+oY1et2uQC+eRcdrfsQ5+v/JB9BZVHz3p72arX0EgLUQ7A9AaOzfgxgcJyAR5gxy6JLHgV3OoM+c3aV87MmOHJesNy08T5WSWM47j+CbiglwUsrUl7joLj0ZQ+AeimovCLHqeZOSVrwSD8lzmN6rFXUPXEjcyS0mhetd5+hrEhACR/h/OlHzIXDsv4W3GW9NdvCJiF74+J95qU/5kRw8rseXnoMM9MSmOqefezcWaxFV4EcXuknCO9TBzhEpZL0FiFmG5GonpXJkmfWgrM7bta+bU7neiGabWqHXvZq7rpc=";
-    private final static String umengMessageSecret = "269f72d7c87938bef3a49dbe14fc4f16";
-    private final static String umengAppMasterSecret = "dlo3bqifmuuvbpmodmcyc2xnh0b1fphi";
+    public final static String umengKey = "62b5753a05844627b5c56bc8";
+    public final static String umengSecret = "+oY1et2uQC+eRcdrfsQ5+v/JB9BZVHz3p72arX0EgLUQ7A9AaOzfgxgcJyAR5gxy6JLHgV3OoM+c3aV87MmOHJesNy08T5WSWM47j+CbiglwUsrUl7joLj0ZQ+AeimovCLHqeZOSVrwSD8lzmN6rFXUPXEjcyS0mhetd5+hrEhACR/h/OlHzIXDsv4W3GW9NdvCJiF74+J95qU/5kRw8rseXnoMM9MSmOqefezcWaxFV4EcXuknCO9TBzhEpZL0FiFmG5GonpXJkmfWgrM7bta+bU7neiGabWqHXvZq7rpc=";
+    public final static String umengMessageSecret = "269f72d7c87938bef3a49dbe14fc4f16";
+    public final static String umengAppMasterSecret = "dlo3bqifmuuvbpmodmcyc2xnh0b1fphi";
 
     private UMVerifyHelper mPhoneNumberAuthHelper;
 
     private boolean sdkAvailable = true;
+    private boolean initiated = false;
 
     @Override
     public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
@@ -118,8 +121,16 @@ public class UmengPlugin extends CordovaPlugin {
     @Override
     public void initialize(CordovaInterface cordova, CordovaWebView webView) {
         super.initialize(cordova, webView);
-        UMConfigure.setLogEnabled(true);
-        UMConfigure.preInit(cordova.getContext(), umengKey, null);
+    }
+
+    public static boolean isAgreed(Application application) {
+        return application.getApplicationContext().getSharedPreferences("umeng_plugin", Context.MODE_PRIVATE).getBoolean("agreed", false);
+    }
+
+    public void setAgreed(boolean agreed) {
+        cordova.getActivity().getApplicationContext().getSharedPreferences("umeng_plugin", Context.MODE_PRIVATE).edit()
+                .putBoolean("agreed", agreed)
+                .apply();
     }
 
     public void login(CallbackContext callbackContext) {
@@ -251,13 +262,17 @@ public class UmengPlugin extends CordovaPlugin {
     }
 
     public void init(CallbackContext callbackContext) {
+        if (initiated) return;
+        if (!isAgreed(cordova.getActivity().getApplication())) {
+            setAgreed(true);
+        }
         UMConfigure.submitPolicyGrantResult(cordova.getContext(), true);
         UMConfigure.init(cordova.getContext(), umengKey, "android", UMConfigure.DEVICE_TYPE_PHONE, umengMessageSecret);
 
         // 微信设置
         PlatformConfig.setWeixin("wx6816dbdc07254dcb", "dc6a12cf5ea483a4d6a303a57b5f6654");
         PlatformConfig.setWXFileProvider(BuildConfig.APPLICATION_ID + ".fileprovider");
-        // QQ设置.                                                                                                                                                                                                                                                                                                                                                                                                  78.
+        // QQ设置
         PlatformConfig.setQQZone("101830139", "5d63ae8858f1caab67715ccd6c18d7a5");
         PlatformConfig.setQQFileProvider(BuildConfig.APPLICATION_ID + ".fileprovider");
         // 新浪微博设置
@@ -295,19 +310,21 @@ public class UmengPlugin extends CordovaPlugin {
         mPhoneNumberAuthHelper.setAuthSDKInfo(umengSecret);
         mPhoneNumberAuthHelper.checkEnvAvailable(UMVerifyHelper.SERVICE_TYPE_LOGIN);
         cordova.getThreadPool().execute(() -> {
-            PushAgent.getInstance(cordova.getContext()).register(new UPushRegisterCallback() {
-                @Override
-                public void onSuccess(String deviceToken) {
-                    Log.i(TAG, "注册成功 deviceToken:" + deviceToken);
-                    callbackContext.success(deviceToken);
-                }
+            initPush(cordova.getContext());
+        });
+    }
 
-                @Override
-                public void onFailure(String errCode, String errDesc) {
-                    Log.e(TAG, "注册失败 " + "code:" + errCode + ", desc:" + errDesc);
-                    callbackContext.error(errDesc);
-                }
-            });
+    public static void initPush(Context context) {
+        PushAgent.getInstance(context).register(new UPushRegisterCallback() {
+            @Override
+            public void onSuccess(String deviceToken) {
+                Log.i(TAG, "注册成功 deviceToken:" + deviceToken);
+            }
+
+            @Override
+            public void onFailure(String errCode, String errDesc) {
+                Log.e(TAG, "注册失败 " + "code:" + errCode + ", desc:" + errDesc);
+            }
         });
     }
 

+ 6 - 2
umeng.gradle

@@ -2,11 +2,13 @@ repositories{
   flatDir {
     dirs 'libs'
   }
+  maven { url 'https://developer.huawei.com/repo/'}
+  maven { url 'https://repo1.maven.org/maven2/' }
 }
 dependencies {
   // 友盟基础组件库(所有友盟业务SDK都依赖基础组件库)
-  implementation 'com.umeng.umsdk:common:9.5.0'// (必选)
-  implementation 'com.umeng.umsdk:asms:1.5.0'// 必选
+  api 'com.umeng.umsdk:common:9.5.0'// (必选)
+  api 'com.umeng.umsdk:asms:1.5.0'// 必选
 
   //友盟Push依赖
   api 'com.umeng.umsdk:push:6.5.2'
@@ -32,6 +34,8 @@ dependencies {
   implementation 'com.umeng.umsdk:uverify-logger:2.1.4'// 必选 
   implementation 'com.umeng.umsdk:uverify-crashshield:2.1.4'// 必选 
   implementation 'com.android.support:appcompat-v7:27.1.1'//(最低版本)
+  api 'com.umeng.umsdk:huawei-umengaccs:1.4.1'
+  api 'com.huawei.hms:push:6.7.0.300'
 }
 android {
     defaultConfig {