Commit 2faa8467 authored by 李增强's avatar 李增强

集成极光厂商版推送-android

parent 8fa0e5f0
# Default ignored files
/shelf/
/workspace.xml
flutter_jpush_vip
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8 (2)" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="http://developer.huawei.com/repo/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://developer.huawei.com/repo/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/flutter_jpush_vip.iml" filepath="$PROJECT_DIR$/.idea/modules/flutter_jpush_vip.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -5,10 +5,12 @@ buildscript { ...@@ -5,10 +5,12 @@ buildscript {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {url 'https://developer.huawei.com/repo/'}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
} }
} }
...@@ -16,10 +18,12 @@ rootProject.allprojects { ...@@ -16,10 +18,12 @@ rootProject.allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {url 'https://developer.huawei.com/repo/'}
} }
} }
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'com.huawei.agconnect'
android { android {
compileSdkVersion 28 compileSdkVersion 28
...@@ -30,6 +34,7 @@ android { ...@@ -30,6 +34,7 @@ android {
} }
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
abortOnError false
} }
...@@ -37,7 +42,12 @@ android { ...@@ -37,7 +42,12 @@ android {
dependencies { dependencies {
api 'cn.jiguang.sdk:jpush:3.9.1' implementation 'cn.jiguang.sdk:jpush:3.9.1'
api 'cn.jiguang.sdk:jcore:2.6.0' implementation 'cn.jiguang.sdk:jcore:2.6.0'
api 'cn.jiguang.sdk.plugin:xiaomi:3.9.1' implementation 'cn.jiguang.sdk.plugin:xiaomi:4.0.0'
implementation 'com.huawei.hms:push:4.0.2.300'
implementation 'cn.jiguang.sdk.plugin:huawei:4.0.0'
implementation 'cn.jiguang.sdk.plugin:oppo:4.0.0'
implementation 'cn.jiguang.sdk.plugin:vivo:4.0.0'
// api files('libs\\com.heytap.msp-push-2.1.0.aar')
} }
\ No newline at end of file
...@@ -12,4 +12,27 @@ ...@@ -12,4 +12,27 @@
-keep class com.google.gson.** {*;} -keep class com.google.gson.** {*;}
-keep class com.google.protobuf.** {*;} -keep class com.google.protobuf.** {*;}
-dontwarn com.xiaomi.push.** -dontwarn com.xiaomi.push.**
-keep class com.xiaomi.push.** { *; } -keep class com.xiaomi.push.** { *; }
\ No newline at end of file
-ignorewarning
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-dontwarn com.coloros.mcsdk.**
-keep class com.coloros.mcsdk.** { *; }
-dontwarn com.heytap.**
-keep class com.heytap.** { *; }
-dontwarn com.mcs.**
-keep class com.mcs.** { *; }
-dontwarn com.vivo.push.**
-keep class com.vivo.push.**{*; }
-keep class com.vivo.vms.**{*; }
\ No newline at end of file
...@@ -37,8 +37,24 @@ ...@@ -37,8 +37,24 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<activity <receiver
android:name=".XActivity" android:name=".XReceiver"
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<service
android:name="cn.jpush.android.service.PluginHuaweiPlatformsService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
</application> </application>
</manifest> </manifest>
package com.qiaomeng.flutter.flutter_jpush_vip; package com.qiaomeng.flutter.flutter_jpush_vip;
import android.app.Activity;
import android.content.Intent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
import cn.jpush.android.ups.TokenResult;
import cn.jpush.android.ups.UPSRegisterCallBack;
import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FlutterJpushVipPlugin */ /**
* FlutterJpushVipPlugin
*/
public class FlutterJpushVipPlugin implements FlutterPlugin, MethodCallHandler { public class FlutterJpushVipPlugin implements FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android /// The MethodChannel that will the communication between Flutter and native Android
/// ///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it /// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity /// when the Flutter Engine is detached from the Activity
private MethodChannel channel; private static MethodChannel channel;
private static Handler handler;
@Override private static String message;
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { private static boolean isInit = false;
channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "flutter_jpush_vip");
channel.setMethodCallHandler(this); @Override
} public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "flutter_jpush_vip");
// This static function is optional and equivalent to onAttachedToEngine. It supports the old channel.setMethodCallHandler(this);
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting handler = new Handler(flutterPluginBinding.getApplicationContext());
// plugin registration via this function while apps migrate to use the new Android APIs
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
//
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_jpush_vip");
channel.setMethodCallHandler(new FlutterJpushVipPlugin());
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else {
result.notImplemented();
} }
}
@Override public static void registerWith(Registrar registrar) {
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_jpush_vip");
channel.setMethodCallHandler(null); channel.setMethodCallHandler(new FlutterJpushVipPlugin());
} }
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) {
if (call.method.equals("init")) {
isInit = true;
onNewIntent(null);
handler.init(new UPSRegisterCallBack() {
@Override
public void onResult(TokenResult tokenResult) {
Map map = new HashMap();
map.put("registrationId", tokenResult.getToken());
map.put("code", tokenResult.getReturnCode());
map.put("actionType", tokenResult.getActionType());
result.success(map);
}
});
} else if (call.method.equals("debug")) {
handler.debug();
result.notImplemented();
} else if (call.method.equals("getRegistrationID")) {
String id = handler.getRegistrationID();
result.success(id);
} else if (call.method.equals("clearAllNotifications")) {
handler.clearAllNotifications();
result.notImplemented();
} else {
result.notImplemented();
}
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
/**
* 监听消息渠道
*
* @param intent
*/
public static void onNewIntent(Intent intent) {
if (isInit && message != null) {
channel.invokeMethod("__JPUSH_MESSAGE__", message);
message = null;
return;
}
if (intent == null) {
return;
}
String msg = handler.getPushMessage(intent);
if (msg == null) {
return;
}
if (isInit) {
channel.invokeMethod("__JPUSH_MESSAGE__", msg);
} else {
message = msg;
}
}
} }
package com.qiaomeng.flutter.flutter_jpush_vip; package com.qiaomeng.flutter.flutter_jpush_vip;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.ups.JPushUPSManager;
import cn.jpush.android.ups.TokenResult;
import cn.jpush.android.ups.UPSRegisterCallBack;
public class Handler { public class Handler {
private Context context; private Context context;
...@@ -11,16 +18,62 @@ public class Handler { ...@@ -11,16 +18,62 @@ public class Handler {
this.context = context; this.context = context;
} }
public void init() { public void init(UPSRegisterCallBack callBack) {
JPushInterface.init(context); JPushUPSManager.registerToken(context, getAppkey(), null, null, callBack);
}
private String getAppkey() {
String value = "";
try {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
value = applicationInfo.metaData.getString("JPUSH_APPKEY");
} catch (Exception e) {
value = "";
}
return value;
} }
public void debug() { public void debug() {
JPushInterface.setDebugMode(true); JPushInterface.setDebugMode(true);
} }
/**
* 获取注册ID
*
* @return
*/
public String getRegistrationID() { public String getRegistrationID() {
return JPushInterface.getRegistrationID(context); return JPushInterface.getRegistrationID(context);
} }
/**
* 清除通知
*/
public void clearAllNotifications() {
JPushInterface.clearAllNotifications(context);
}
/**
* 点击通知时获取消息
*
* @param intent
* @return
*/
public String getPushMessage(Intent intent) {
String data = null;
//获取华为平台附带的jpush信息
if (intent.getData() != null) {
data = intent.getData().toString();
}
//获取fcm、oppo、vivo、华硕、小米平台附带的jpush信息
if (TextUtils.isEmpty(data) && intent.getExtras() != null) {
data = intent.getExtras().getString("JMessageExtra");
}
return data;
}
} }
package com.qiaomeng.flutter.flutter_jpush_vip;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
import androidx.annotation.Nullable;
public class XActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
...@@ -4,11 +4,40 @@ import android.content.Context; ...@@ -4,11 +4,40 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import org.json.JSONException;
import org.json.JSONObject;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage; import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver; import cn.jpush.android.service.JPushMessageReceiver;
public class XReceiver extends JPushMessageReceiver { public class XReceiver extends JPushMessageReceiver {
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
String msgId = notificationMessage.msgId;
String title = notificationMessage.notificationTitle;
String content = notificationMessage.notificationContent;
String extras = notificationMessage.notificationExtras;
int platform = notificationMessage.platform;
JSONObject json = new JSONObject();
try {
json.put("msg_id", msgId);
json.put("n_title", title);
json.put("n_content", content);
json.put("n_extras", new JSONObject(extras));
json.put("rom_type", platform);
} catch (JSONException e) {
e.printStackTrace();
}
// intent.getExtras().getString
String jpush = json.toString();
Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getApplicationContext().getPackageName());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle = new Bundle();
bundle.putString("JMessageExtra", jpush);
i.putExtras(bundle);
context.startActivity(i);
}
} }
{
"agcgw":{
"backurl":"connect-drcn.dbankcloud.cn",
"url":"connect-drcn.hispace.hicloud.com",
"websocketbackurl":"connect-ws-drcn.hispace.dbankcloud.cn",
"websocketurl":"connect-ws-drcn.hispace.dbankcloud.com"
},
"agcgw_all":{
"CN":"connect-drcn.hispace.hicloud.com",
"CN_back":"connect-drcn.dbankcloud.cn",
"DE":"connect-dre.hispace.hicloud.com",
"DE_back":"connect-dre.dbankcloud.cn",
"RU":"connect-drru.hispace.hicloud.com",
"RU_back":"connect-drru.dbankcloud.cn",
"SG":"connect-dra.hispace.hicloud.com",
"SG_back":"connect-dra.dbankcloud.cn"
},
"client":{
"cp_id":"890086000102083695",
"product_id":"9105163812218451550",
"client_id":"270687076884677824",
"client_secret":"CB3F7553B850B403139BC1C2ED3DC5522117DCE7AE36724304C87BC7A9C0D920",
"project_id":"9105163812218451550",
"app_id":"100103671",
"api_key":"CV5FGM+ewUXF9PnV2OE7tULgogRO9wFORzqC/JjOCzUICHbOBTPQWc5ZfBrKc3AZvciRRlGb2xnvZs0laEtWOnsjd3OH",
"package_name":"com.xiaoxiongyhh"
},
"service":{
"analytics":{
"collector_url":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
"resource_id":"p1",
"channel_id":""
},
"search":{
"url":"https://search-drcn.cloud.huawei.com"
},
"cloudstorage":{
"storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn"
},
"ml":{
"mlservice_url":"ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"
}
},
"region":"CN",
"configuration_version":"2.0",
"appInfos":[
{
"package_name":"com.xiaoxiongyhh",
"app_id":"100103671"
}
]
}
\ No newline at end of file
...@@ -21,20 +21,28 @@ if (flutterVersionName == null) { ...@@ -21,20 +21,28 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = '1.0'
} }
def keystorePropertiesFile = rootProject.file("key/keystore.properties");
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists()) {
keystorePropertiesFile.withReader('UTF-8') { reader ->
keystoreProperties.load(reader)
}
}
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion 28 compileSdkVersion 28
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
abortOnError false
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.xiaoxiongyhh" applicationId "com.xiaoxiongyhh"
minSdkVersion 16 minSdkVersion 19
targetSdkVersion 28 targetSdkVersion 28
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
...@@ -45,16 +53,37 @@ android { ...@@ -45,16 +53,37 @@ android {
JPUSH_CHANNEL: "00186a85d6e044ecce1406a8", //暂时填写默认值即可. JPUSH_CHANNEL: "00186a85d6e044ecce1406a8", //暂时填写默认值即可.
XIAOMI_APPKEY : "MI-5651762211854", // 小米平台注册的appkey XIAOMI_APPKEY : "MI-5651762211854", // 小米平台注册的appkey
XIAOMI_APPID : "MI-2882303761517622854", // 小米平台注册的appid XIAOMI_APPID : "MI-2882303761517622854", // 小米平台注册的appid
OPPO_APPKEY : "OP-cWtlupo7k6goCWGs8kCcoGw44", // OPPO平台注册的appkey
OPPO_APPID : "OP-3597314", // OPPO平台注册的appid
OPPO_APPSECRET: "OP-6d91f494e2C8752910cEd15571Af8893", //OPPO平台注册的appsecret
VIVO_APPKEY : "c88ba5d2-38f7-4286-b512-3bcd5834f3c1", // VIVO平台注册的appkey
VIVO_APPID : "16048", // VIVO平台注册的appid
"com.huawei.hms.client.appid": "appid=100103671", // 华为
] ]
} }
buildTypes { signingConfigs {
release { release {
storeFile file(keystoreProperties.getProperty("storeFile"))
storePassword keystoreProperties.getProperty('storePassword')
keyAlias keystoreProperties.getProperty('keyAlias')
keyPassword keystoreProperties.getProperty('keyPassword')
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
deubg {
minifyEnabled false
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig signingConfigs.release
} }
} }
......
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.qiaomeng.flutter.flutter_jpush_vip_example"> package="com.qiaomeng.flutter.flutter_jpush_vip_example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method. calls FlutterMain.startInitialization(this); in its onCreate method.
...@@ -7,36 +8,42 @@ ...@@ -7,36 +8,42 @@
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here. -->
<application <application
android:name="io.flutter.app.FlutterApplication" android:name="io.flutter.app.FlutterApplication"
android:debuggable="true"
android:icon="@mipmap/ic_launcher"
android:label="flutter_jpush_vip_example" android:label="flutter_jpush_vip_example"
android:icon="@mipmap/ic_launcher"> tools:ignore="HardcodedDebugMode"
tools:replace="android:label">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize" android:launchMode="singleTask"
android:exported="true"> android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as <!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. --> to determine the Window background behind the Flutter UI. -->
<meta-data <meta-data
android:name="io.flutter.embedding.android.NormalTheme" android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" android:resource="@style/NormalTheme" />
/>
<!-- Displays an Android View that continues showing the launch screen <!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of gap between the end of Android's launch screen and the painting of
Flutter's first frame. --> Flutter's first frame. -->
<meta-data <meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable" android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" android:resource="@drawable/launch_background" />
/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="com.example.jpushdemo.OpenClickActivity" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
...@@ -44,15 +51,13 @@ ...@@ -44,15 +51,13 @@
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="100103671" />
<meta-data
android:name="com.huawei.hms.client.cpid"
android:value="890086000102083695" />
<receiver
android:name=".XXXReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>
...@@ -7,130 +7,49 @@ import android.text.TextUtils; ...@@ -7,130 +7,49 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.qiaomeng.flutter.flutter_jpush_vip.Handler; import com.qiaomeng.flutter.flutter_jpush_vip.FlutterJpushVipPlugin;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import cn.jpush.android.api.JPushInterface;
import io.flutter.Log; import io.flutter.Log;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
Handler handler = new Handler(this); /**
* 消息Id
private static final String TAG = "OpenClickActivity"; **/
/**消息Id**/
private static final String KEY_MSGID = "msg_id"; private static final String KEY_MSGID = "msg_id";
/**该通知的下发通道**/ /**
* 该通知的下发通道
**/
private static final String KEY_WHICH_PUSH_SDK = "rom_type"; private static final String KEY_WHICH_PUSH_SDK = "rom_type";
/**通知标题**/ /**
* 通知标题
**/
private static final String KEY_TITLE = "n_title"; private static final String KEY_TITLE = "n_title";
/**通知内容**/ /**
* 通知内容
**/
private static final String KEY_CONTENT = "n_content"; private static final String KEY_CONTENT = "n_content";
/**通知附加字段**/ /**
* 通知附加字段
**/
private static final String KEY_EXTRAS = "n_extras"; private static final String KEY_EXTRAS = "n_extras";
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
handler.debug(); FlutterJpushVipPlugin.onNewIntent(getIntent());
handler.init();
// handleOpenClick();
} }
@Override @Override
protected void onNewIntent(@NonNull Intent intent) { protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
System.out.println("========================"+intent.getExtras()); FlutterJpushVipPlugin.onNewIntent(intent);
} }
/**
* 处理点击事件,当前启动配置的Activity都是使用
* Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
* 方式启动,只需要在onCreat中调用此方法进行处理
*/
private void handleOpenClick() {
Log.d(TAG, "用户点击打开了通知");
String data = null;
//获取华为平台附带的jpush信息
if (getIntent().getData() != null) {
data = getIntent().getData().toString();
}
//获取fcm、oppo、vivo、华硕、小米平台附带的jpush信息
if(TextUtils.isEmpty(data) && getIntent().getExtras() != null){
data = getIntent().getExtras().getString("JMessageExtra");
}
System.out.println("==================="+getIntent());
Log.w(TAG, "msg content is " + String.valueOf(data));
if (TextUtils.isEmpty(data)) return;
try {
JSONObject jsonObject = new JSONObject(data);
String msgId = jsonObject.optString(KEY_MSGID);
byte whichPushSDK = (byte) jsonObject.optInt(KEY_WHICH_PUSH_SDK);
String title = jsonObject.optString(KEY_TITLE);
String content = jsonObject.optString(KEY_CONTENT);
String extras = jsonObject.optString(KEY_EXTRAS);
StringBuilder sb = new StringBuilder();
sb.append("msgId:");
sb.append(String.valueOf(msgId));
sb.append("\n");
sb.append("title:");
sb.append(String.valueOf(title));
sb.append("\n");
sb.append("content:");
sb.append(String.valueOf(content));
sb.append("\n");
sb.append("extras:");
sb.append(String.valueOf(extras));
sb.append("\n");
sb.append("platform:");
sb.append(getPushSDKName(whichPushSDK));
Log.w(TAG, sb.toString());
//上报点击事件
JPushInterface.reportNotificationOpened(this, msgId, whichPushSDK);
} catch (JSONException e) {
Log.w(TAG, "parse notification error");
}
}
private String getPushSDKName(byte whichPushSDK) {
String name;
switch (whichPushSDK){
case 0:
name = "jpush";
break;
case 1:
name = "xiaomi";
break;
case 2:
name = "huawei";
break;
case 3:
name = "meizu";
break;
case 4:
name= "oppo";
break;
case 5:
name = "vivo";
break;
case 6:
name = "asus";
break;
case 8:
name = "fcm";
break;
default:
name = "jpush";
}
return name;
}
} }
package com.qiaomeng.flutter.flutter_jpush_vip_example;
import android.content.Context;
import android.content.Intent;
import com.qiaomeng.flutter.flutter_jpush_vip.XReceiver;
import cn.jpush.android.api.NotificationMessage;
public class XXXReceiver extends XReceiver {
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
// System.out.println("========"+notificationMessage.toString());
Intent i = new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
}
storeFile=../key/key.keystore
storePassword=yawei819
keyAlias=小熊有好货
keyPassword=yawei819
\ No newline at end of file
...@@ -14,33 +14,19 @@ class MyApp extends StatefulWidget { ...@@ -14,33 +14,19 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
} FlutterJpushVip.init().then((value) {
print("============$value");
// Platform messages are asynchronous, so we initialize in an async method. });
Future<void> initPlatformState() async { FlutterJpushVip.onNotification((n){
String platformVersion; print("============$n");
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await FlutterJpushVip.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// 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.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
...@@ -50,10 +36,10 @@ class _MyAppState extends State<MyApp> { ...@@ -50,10 +36,10 @@ class _MyAppState extends State<MyApp> {
), ),
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
initPlatformState();
}, },
child: Center( child: Center(
child: Text('Running on: $_platformVersion\n'), child: Text('Running on: test'),
)), )),
), ),
); );
......
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.0"
async: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.4.1" version: "2.5.0-nullsafety.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety.1"
charcode: characters:
dependency: transitive dependency: transitive
description: description:
name: charcode name: characters
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.3" version: "1.1.0-nullsafety.3"
collection: charcode:
dependency: transitive dependency: transitive
description: description:
name: collection name: charcode
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.14.12" version: "1.2.0-nullsafety.1"
convert: clock:
dependency: transitive dependency: transitive
description: description:
name: convert name: clock
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.1" version: "1.1.0-nullsafety.1"
crypto: collection:
dependency: transitive dependency: transitive
description: description:
name: crypto name: collection
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.4" version: "1.15.0-nullsafety.3"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -64,6 +50,13 @@ packages: ...@@ -64,6 +50,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.1.3" version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -95,41 +88,27 @@ packages: ...@@ -95,41 +88,27 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.12"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.12.6" version: "0.12.10-nullsafety.1"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0-nullsafety.3"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.6.4" version: "1.8.0-nullsafety.1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
platform: platform:
dependency: transitive dependency: transitive
description: description:
...@@ -144,13 +123,6 @@ packages: ...@@ -144,13 +123,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.3" version: "1.0.3"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.3"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -162,42 +134,42 @@ packages: ...@@ -162,42 +134,42 @@ packages:
name: source_span name: source_span
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.7.0" version: "1.8.0-nullsafety.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.9.3" version: "1.10.0-nullsafety.1"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety.1"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.5" version: "1.1.0-nullsafety.1"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0-nullsafety.1"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.2.15" version: "0.2.19-nullsafety.2"
timezone: timezone:
dependency: transitive dependency: transitive
description: description:
...@@ -211,21 +183,14 @@ packages: ...@@ -211,21 +183,14 @@ packages:
name: typed_data name: typed_data
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.6" version: "1.3.0-nullsafety.3"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.8" version: "2.1.0-nullsafety.3"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.6.1"
sdks: sdks:
dart: ">=2.7.0 <3.0.0" dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5" flutter: ">=1.12.13+hotfix.5"
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -6,8 +7,51 @@ class FlutterJpushVip { ...@@ -6,8 +7,51 @@ class FlutterJpushVip {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('flutter_jpush_vip'); const MethodChannel('flutter_jpush_vip');
static Future<String> get platformVersion async { static Future<Map> init() {
final String version = await _channel.invokeMethod('getPlatformVersion'); return _channel.invokeMethod('init');
return version; }
static void debug() {
_channel.invokeMethod('debug');
}
static Future<String> getRegistrationID() {
return _channel.invokeMethod('getRegistrationID');
}
static void clearAllNotifications() {
_channel.invokeMethod('clearAllNotifications');
}
static void onNotification(Function(Notification notification) callback) {
_channel.setMethodCallHandler((call) {
if (call.method == '__JPUSH_MESSAGE__') {
Map map = json.decode(call.arguments);
var n = Notification.from(map);
callback(n);
}
return null;
});
}
}
class Notification {
String msgId;
String content;
String title;
Map extras;
int platform;
Notification.from(Map map) {
msgId = map['msg_id'];
content = map['n_content'];
title = map['n_title'];
extras = map['n_extras'];
platform = map['rom_type'];
}
@override
String toString() {
return 'Notification{msgId: $msgId, content: $content, title: $title, extras: $extras, platform: $platform}';
} }
} }
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_jpush_vip/flutter_jpush_vip.dart';
void main() {
const MethodChannel channel = MethodChannel('flutter_jpush_vip');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
test('getPlatformVersion', () async {
expect(await FlutterJpushVip.platformVersion, '42');
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment