Procházet zdrojové kódy

部分代码修改

linbing před 5 roky
rodič
revize
9aaeb70ffb

+ 7 - 2
android/build.gradle

@@ -55,10 +55,15 @@ android {
 }
 
 dependencies {
-    implementation 'com.aliyun.ams:alicloud-android-push:3.1.9.1@aar'
-//    implementation 'com.aliyun.ams:alicloud-android-third-push:3.+@aar'
+
+    implementation 'com.aliyun.ams:alicloud-android-push:3.1.10@aar'
+    implementation'com.aliyun.ams:alicloud-android-third-push:3.1.0@aar'
     implementation 'com.aliyun.ams:alicloud-android-utdid:1.5.2'
     implementation 'com.aliyun.ams:alicloud-android-utils:1.1.6.4'
     implementation 'com.aliyun.ams:alicloud-android-ut:5.4.3'
     implementation 'com.aliyun.ams:alicloud-android-beacon:1.0.4.3'
+    implementation 'com.aliyun.ams:huawei-push:2.6.3.305'
+    implementation 'com.aliyun.ams:huawei-push-base:2.6.3.305'
+    implementation 'com.aliyun.ams:meizu-push:3.8.7.1'
+    implementation 'com.aliyun.ams:third_vivopush:2.9.0.1'
 }

+ 34 - 0
android/src/main/AndroidManifest.xml

@@ -16,5 +16,39 @@
         >
         <meta-data android:name="com.alibaba.app.appkey" android:value="${aliyunPushAppKey}"/> <!-- 请填写你自己的- appKey -->
         <meta-data android:name="com.alibaba.app.appsecret" android:value="${aliyunPushAppSecret}"/> <!-- 请填写你自己的appSecret -->
+
+        <meta-data
+            android:name="com.huawei.hms.client.appid"
+            android:value="${huaweiPushAppId}" />
+
+        <meta-data
+            android:name="com.vivo.push.api_key"
+            android:value="${vivoPushAppKey}" />
+        <meta-data
+            android:name="com.vivo.push.app_id"
+            android:value="${vivoPushAppId}" />
+
+
+        <!-- 自定义,统一初始化 -->
+        <meta-data
+            android:name="com.mi.push.api_key"
+            android:value="${miPushAppKey}" />
+        <meta-data
+            android:name="com.mi.push.app_id"
+            android:value="${miPushAppId}" />
+
+        <meta-data
+            android:name="com.oppo.push.api_key"
+            android:value="${oppoPushAppKey}" />
+        <meta-data
+            android:name="com.oppo.push.app_secret"
+            android:value="${oppoPushAppSecret}" />
+
+        <meta-data
+            android:name="com.meizhu.push.api_key"
+            android:value="${meizhuPushAppKey}" />
+        <meta-data
+            android:name="com.meizhu.push.app_id"
+            android:value="${meizhuPushAppId}" />
     </application>
 </manifest>

+ 133 - 2
android/src/main/java/com/flutter/flutter_aliyun_push/FlutterAliyunPushPlugin.java

@@ -1,12 +1,24 @@
 package com.flutter.flutter_aliyun_push;
 
+import android.app.Application;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.os.Build;
 
 import androidx.annotation.NonNull;
 
 import com.alibaba.sdk.android.push.CloudPushService;
 import com.alibaba.sdk.android.push.CommonCallback;
+import com.alibaba.sdk.android.push.huawei.HuaWeiRegister;
 import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
+import com.alibaba.sdk.android.push.register.MeizuRegister;
+import com.alibaba.sdk.android.push.register.MiPushRegister;
+import com.alibaba.sdk.android.push.register.OppoRegister;
+import com.alibaba.sdk.android.push.register.VivoRegister;
 
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -23,12 +35,18 @@ import io.flutter.plugin.common.StandardMethodCodec;
 
 public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
 
-  private static FlutterAliyunPushPlugin instance;
+  public static FlutterAliyunPushPlugin instance;
   public static final String TAG = "AliyunPushPlugin";
   public static final String CHANNEL_NAME="aliyun_push";
   private Context context;
-  private Object initializationLock = new Object();
+  public static Object initializationLock = new Object();
   private MethodChannel aliyunPushPluginChannel;
+  private static String lastPushRegistSuccessMessage;
+  private static String lastPushRegistErrorMessage;
+
+  public MethodChannel getAliyunPushPluginChannel() {
+    return aliyunPushPluginChannel;
+  }
 
   public FlutterAliyunPushPlugin() {}
 
@@ -41,22 +59,125 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
 
   public static void initPush(Context context) {
     Log.i(TAG, "start initPush");
+    if (instance == null) {
+      instance = new FlutterAliyunPushPlugin();
+    }
     PushServiceFactory.init(context);
+    initPushVersion(context);
     CloudPushService pushService = PushServiceFactory.getCloudPushService();
     pushService.register(context, new CommonCallback() {
       @Override
       public void onSuccess(String response) {
         Log.d(FlutterAliyunPushPlugin.TAG, "init cloudchannel success");
+        synchronized (initializationLock) {
+          if(instance.getAliyunPushPluginChannel() != null) {
+            instance.getAliyunPushPluginChannel().invokeMethod("onPushRegistSuccess",response);
+          }else {
+            Log.d(FlutterAliyunPushPlugin.TAG, "instance.aliyunPushPluginChannel null");
+            lastPushRegistSuccessMessage = response;
+            lastPushRegistErrorMessage = null;
+          }
+        }
+
       }
       @Override
       public void onFailed(String errorCode, String errorMessage) {
         Log.d(FlutterAliyunPushPlugin.TAG, "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
+        if(instance.getAliyunPushPluginChannel() != null) {
+          instance.getAliyunPushPluginChannel().invokeMethod("onPushRegistError",errorMessage);
+        }else {
+          lastPushRegistErrorMessage = errorMessage;
+          lastPushRegistSuccessMessage = null;
+        }
       }
     });
+  }
+
+  /**
+   * 初始化厂商推送
+   */
+  public static void initThirdPush(Context context) {
+    ThirdPushConfig config = new ThirdPushConfig();
+
+    ApplicationInfo appInfo = null;
+    try {
+      appInfo = context.getPackageManager()
+              .getApplicationInfo(context.getPackageName(),
+                      PackageManager.GET_META_DATA);
+    } catch (PackageManager.NameNotFoundException e) {
+      e.printStackTrace();
+    }
+    if(appInfo == null) {
+      return;
+    }
+    config.miPushAppId = appInfo.metaData.getString("com.mi.push.app_id");
+    config.miPushAppKey = appInfo.metaData.getString("com.mi.push.api_key");
+
+    config.huaweiPushAppId = appInfo.metaData.getString("com.huawei.hms.client.appid");
+
+    config.vivoPushAppId = appInfo.metaData.getString("com.vivo.push.app_id");
+    config.vivoPushAppKey = appInfo.metaData.getString("com.vivo.push.api_key");
+
+    config.oppoPushAppKey = appInfo.metaData.getString("com.oppo.push.api_key");
+    config.oppoPushAppSecret = appInfo.metaData.getString("com.oppo.push.app_secret");
+
+    config.meizhuPushAppId = appInfo.metaData.getString("com.meizhu.push.app_id");
+    config.meizhuPushAppKey = appInfo.metaData.getString("com.meizhu.push.api_key");
 
+    // 注册方法会自动判断是否支持小米系统推送,如不支持会跳过注册。
+    if(config.miPushAppId != null && config.miPushAppKey != null) {
+      MiPushRegister.register(context, config.miPushAppId, config.miPushAppKey);
+    }
+
+    // 注册方法会自动判断是否支持华为系统推送,如不支持会跳过注册。
+    if(config.huaweiPushAppId != null) {
+      HuaWeiRegister.register((Application) context);
+    }
+
+    // OPPO通道注册
+    if(config.oppoPushAppKey != null && config.oppoPushAppSecret != null) {
+      OppoRegister.register(context, config.oppoPushAppKey, config.oppoPushAppSecret); // appKey/appSecret在OPPO开发者平台获取
+    }
+
+    // 魅族通道注册
+    if(config.meizhuPushAppId != null && config.meizhuPushAppKey != null) {
+      MeizuRegister.register(context, config.meizhuPushAppId, config.meizhuPushAppKey); // appId/appkey在魅族开发者平台获取
+    }
+
+    // VIVO通道注册
+    if(config.vivoPushAppId != null && config.vivoPushAppKey != null) {
+      VivoRegister.register(context);
+    }
+
+  }
+
+  private static void initPushVersion(Context context) {
+//    GcmRegister.register(this, "851061211440", "api-8646462459812937352-2848");
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+      NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+      // 通知渠道的id
+      String id = "1";
+      // 用户可以看到的通知渠道的名字.
+      CharSequence name = "notification channel";
+      // 用户可以看到的通知渠道的描述
+      String description = "notification description";
+      int importance = NotificationManager.IMPORTANCE_HIGH;
+      NotificationChannel mChannel = new NotificationChannel(id, name, importance);
+      // 配置通知渠道的属性
+      mChannel.setDescription(description);
+      // 设置通知出现时的闪灯(如果 android 设备支持的话)
+      mChannel.enableLights(true);
+      mChannel.setLightColor(Color.RED);
+      // 设置通知出现时的震动(如果 android 设备支持的话)
+      mChannel.enableVibration(true);
+      mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
+      //最后在notificationmanager中创建该通知渠道
+      mNotificationManager.createNotificationChannel(mChannel);
+    }
   }
 
 
+
   @Override
   public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
     onAttachedToEngine(binding.getApplicationContext(), binding.getBinaryMessenger());
@@ -87,6 +208,16 @@ public class FlutterAliyunPushPlugin implements FlutterPlugin, MethodChannel.Met
       // Instantiate a new Plugin and connect the primary method channel for
       // Android/Flutter communication.
       aliyunPushPluginChannel.setMethodCallHandler(this);
+
+      if(lastPushRegistSuccessMessage != null) {
+        Log.i(TAG, "invokeMethod:"+ "onPushRegistSuccess");
+        aliyunPushPluginChannel.invokeMethod("onPushRegistSuccess",lastPushRegistSuccessMessage);
+        lastPushRegistSuccessMessage = null;
+      }else if(lastPushRegistErrorMessage != null) {
+        Log.i(TAG, "invokeMethod:"+ "onPushRegistError");
+        aliyunPushPluginChannel.invokeMethod("onPushRegistError",lastPushRegistErrorMessage);
+        lastPushRegistErrorMessage = null;
+      }
 //      aliyunPushPluginChannel.invokeMethod("onPushInit",null);
 
     }

+ 19 - 0
android/src/main/java/com/flutter/flutter_aliyun_push/ThirdPushConfig.java

@@ -0,0 +1,19 @@
+package com.flutter.flutter_aliyun_push;
+
+public class ThirdPushConfig {
+    public String huaweiPushAppId;//华为推送appid
+
+    public  String vivoPushAppId; //vivo推送appid
+    public  String vivoPushAppKey; //vivo推送appkey
+
+    public  String miPushAppId; //小米推送appid
+    public  String miPushAppKey; //小米推送appkey
+
+    public String oppoPushAppKey;//oppo推送appkey
+    public String oppoPushAppSecret;//oppo推送ppSecret
+
+    public  String meizhuPushAppId; //魅族推送appid
+    public  String meizhuPushAppKey; //魅族推送appkey
+
+
+}

+ 8 - 8
example/android/app/aliyun-emas-services.json

@@ -1,14 +1,14 @@
 {
   "config": {
-	"emas.appKey":"30543515",
-	"emas.appSecret":"ee0268fd22f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a3SjSN2nJxABtilkhdIZ00TuM1BLt1T0TtwdKGL3zPQXKGH+3eNVavY+13FrwEl+VBtJt2BVhW6ofhGTeqaThYwnTSn/MTfnIG/wKBgFg6VUItnZ4yPr9ZyTDjleZ38uoy+Iv64J8nNObK4b3tcJ15Wsg30xHW6sVKFhrnggud3ckIVkbm7DnMDrxXrHedexT8xayMEsbnejPV8EfTJUpfoH/R96D/NncV01f6Za3jS6EE36NufeMoF0rFkYOku/LfQ3vl2EN+F8Q0GxDxAoGBAMv9sEqtDNQwjP6E3Sg8wcg5/Mm40I5yw4oKz7U7ATN3liNyaBSuxsZb0dz39NIc2H/epfw6AgSw9N4O5MGQz1++YtVq+dC5Qf2n+BjAsBgLsWPbVzYzNcwHoOIVKn9DGBksvizul9J5Lu18+JgYAy9GtWHoPEvkjzObsW2d1+JVAoGBALSK0/CUwhYWThG4zsgC+Z0DJkECq484N9awQ2TRPycT5Pbs8/yD6zgLiJdqMJtLDgD6gnBEsN9PQIZ+UxcfTGNqMuRECApMSzJg4HmPqpFGfVNHA1AbbzhoCkXAp01Ao9WN/T15VZp973Xvr0sJ8oaYA/2vnM0kO2WYiyxTrcqE",
+	"emas.appKey":"30734536",
+	"emas.appSecret":"0983be97e631d6ae01e666409a998921",
+	"emas.packageName":"com.flutter.aliPush",
+	"hotfix.idSecret":"30734536-1",
+	"hotfix.rsaSecret":"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCWr+AIXs9hACAAQAimueYlxRqLViolPzsYKnqFhcnL+lrjBb85DJRyY7y7UMPBnOvisyMLExelw2ev9DGZSGuo+7vLQpbypQtLAnX7JJq5rk8nRG3/8/UKnhoW4qMR7PTija3ErrKK6E1COKirINQXU2ekyfz4W3WL59asf59VSFPYs7jlZ835m9fJCR56DG2fF7K8Ctycby0dgC+alTwB1qtvuplL8ISVNzuFqOm0K0VIgGaKoWLvli6ezaKJlbRIn5UURMUmjQywdPRyytKJ4lWGFnGoujaTOYEDrOacY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4oU1GeyFdNOx7185ThKli22QKBgDM+fP77UND2IDYrPi6zL1x0EZL7DKPYZTYMi/2C7NsbC0UziajDsVhsGT/DYLZyT5qK1bxqhukuUjCtBMkkKTlS4Td2yLwpWsgRxgq71o9rvPMjqLHqEqZU9RK33p9xwQUhlk7FuQXXDjoNS0yn0ZXDxy1gTvdyfPbwOjXSk8HA",
 	"httpdns.accountId":"137350",
 	"httpdns.secretKey":"12d1510955b12671ad5787640ffa5a63",
-	"appmonitor.tlog.rsaSecret":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD5IlORQKELpOpwbU27hze2sSuk8q6RuPldsyYjQxWNCHaeEn/oLbE/+O3+ph83AzGOjvy5LxcwxeA2iY/MFI6TgqrSOJucIbUxLVub37TnSimhAP9hQOIi3FpbZbi8z7p+9a6bjny1WJbS/eOB+jLt6MFApIkVDoHM6lx8xNRVewIDAQAB",
-	"appmonitor.rsaSecret":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD5IlORQKELpOpwbU27hze2sSuk8q6RuPldsyYjQxWNCHaeEn/oLbE/+O3+ph83AzGOjvy5LxcwxeA2iY/MFI6TgqrSOJucIbUxLVub37TnSimhAP9hQOIi3FpbZbi8z7p+9a6bjny1WJbS/eOB+jLt6MFApIkVDoHM6lx8xNRVewIDAQAB"
+	"appmonitor.tlog.rsaSecret":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAQPjGUMQh68NunMb19jSiXJvWarHPXbKFDYMNpVRWquF9iV+qtdb6JRVZh+pJvCLXIAveyqH4BQiZPg6CRHELZnLjkWRpQnPvA7mms34v+v3tQRWNBmJiV+meUnb15MGC4EvUbYpFQdLDmweMRho3bnDVp1qPk/kFT52j7MCl9wIDAQAB",
+	"appmonitor.rsaSecret":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAQPjGUMQh68NunMb19jSiXJvWarHPXbKFDYMNpVRWquF9iV+qtdb6JRVZh+pJvCLXIAveyqH4BQiZPg6CRHELZnLjkWRpQnPvA7mms34v+v3tQRWNBmJiV+meUnb15MGC4EvUbYpFQdLDmweMRho3bnDVp1qPk/kFT52j7MCl9wIDAQAB"
 },
   "services": {
 	"hotfix_service":{
@@ -41,7 +41,7 @@
 	},
 	"cps_service":{
 		"status":1,
-		"version":"3.1.9.1"
+		"version":"3.1.10"
 	}
 },
   "use_maven":true,

+ 12 - 3
example/android/app/build.gradle

@@ -33,7 +33,7 @@ android {
 
     defaultConfig {
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
-        applicationId "com.flutter.aliyunPush"
+        applicationId "com.flutter.aliPush"
         minSdkVersion 16
         targetSdkVersion 28
         versionCode flutterVersionCode.toInteger()
@@ -41,8 +41,17 @@ android {
 
 
         manifestPlaceholders = [
-                aliyunPushAppKey: "30543515",
-                aliyunPushAppSecret:"ee0268fd22fcfd66fb416163b235dd29"
+                aliyunPushAppKey: "30734536", //阿里云推送appkey
+                aliyunPushAppSecret:"0983be97e631d6ae01e666409a998921",//阿里云推送appsecret
+                miPushAppId:"123", //小米推送Appid
+                miPushAppKey:"456", //小米推送AppKey
+                huaweiPushAppId:"789", //华为推送AppId
+                vivoPushAppId:"012", //vivo推送AppId
+                vivoPushAppKey:"345", //vivo推送AppKey
+                oppoPushAppKey:"678", //oppo推送AppKey
+                oppoPushAppSecret:"901", //oppo推送AppKey
+                meizhuPushAppId:"234",  //魅族推送AppId
+                meizhuPushAppKey:"567",//魅族推送AppKey
         ]
 
 

+ 6 - 1
example/lib/main.dart

@@ -24,15 +24,20 @@ class _MyAppState extends State<MyApp> {
 
   // Platform messages are asynchronous, so we initialize in an async method.
   Future<void> initPlatformState() async {
+
     String platformVersion;
     // Platform messages may fail, so we use a try/catch PlatformException.
     try {
       platformVersion = await FlutterAliyunPush.platformVersion;
-      await FlutterAliyunPush.initPush;
+//      await FlutterAliyunPush.initPush;
     } on PlatformException {
       platformVersion = 'Failed to get platform version.';
     }
 
+    FlutterAliyunPush.reigistOnRegistSuccess((msg){
+      platformVersion = msg;
+    });
+
     // If the widget was removed from the tree while the asynchronous platform
     // message was in flight, we want to discard the reply rather than calling
     // setState to update our non-existent appearance.

+ 3 - 1
example/test/widget_test.dart

@@ -13,7 +13,9 @@ import 'package:flutter_aliyun_push_example/main.dart';
 void main() {
   testWidgets('Verify Platform version', (WidgetTester tester) async {
     // Build our app and trigger a frame.
-    await tester.pumpWidget(MyApp());
+    await tester.pumpW
+
+    idget(MyApp());
 
     // Verify that platform version is retrieved.
     expect(

+ 40 - 0
lib/flutter_aliyun_push.dart

@@ -5,6 +5,10 @@ import 'package:flutter/services.dart';
 class FlutterAliyunPush {
   static const MethodChannel _channel =
       const MethodChannel('aliyun_push');
+  static bool registCallback = false;
+
+  static Function onRegistSuccess;
+  static Function onRegistError;
 
   static Future<String> get platformVersion async {
     final String version = await _channel.invokeMethod('getPlatformVersion');
@@ -15,6 +19,42 @@ class FlutterAliyunPush {
     final String version = await _channel.invokeMethod('initPush');
     return version;
   }
+
+  /**
+   * 注册原生调用dart
+   */
+  static  void registCallHandler() {
+    if(registCallback) {
+      return;
+    }
+    registCallback = true;
+    _channel.setMethodCallHandler((call) {
+      print("setMethodCallHandler:"+call.method);
+      switch(call.method) {
+        case "onPushRegistSuccess":
+          if(onRegistSuccess != null) {
+            onRegistSuccess(call.arguments);
+          }
+          break;
+        case "onPushRegistError":
+          if(onRegistError != null) {
+            onRegistError(call.arguments);
+          }
+          break;
+      }
+    });
+  }
+
+  static void  reigistOnRegistSuccess(Function callback) {
+    onRegistSuccess = callback;
+    registCallHandler();
+  }
+
+
+  static void  reigistOnRegistError(Function callback) {
+    onRegistError = callback;
+    registCallHandler();
+  }
 }