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 {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
......@@ -16,10 +18,12 @@ rootProject.allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.huawei.agconnect'
android {
compileSdkVersion 28
......@@ -30,6 +34,7 @@ android {
}
lintOptions {
disable 'InvalidPackage'
abortOnError false
}
......@@ -37,7 +42,12 @@ android {
dependencies {
api 'cn.jiguang.sdk:jpush:3.9.1'
api 'cn.jiguang.sdk:jcore:2.6.0'
api 'cn.jiguang.sdk.plugin:xiaomi:3.9.1'
implementation 'cn.jiguang.sdk:jpush:3.9.1'
implementation 'cn.jiguang.sdk:jcore:2.6.0'
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
......@@ -13,3 +13,26 @@
-keep class com.google.protobuf.** {*;}
-dontwarn com.xiaomi.push.**
-keep class com.xiaomi.push.** { *; }
-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 @@
</intent-filter>
</receiver>
<activity
android:name=".XActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<receiver
android:name=".XReceiver"
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>
</manifest>
package com.qiaomeng.flutter.flutter_jpush_vip;
import android.app.Activity;
import android.content.Intent;
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.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FlutterJpushVipPlugin */
/**
* FlutterJpushVipPlugin
*/
public class FlutterJpushVipPlugin implements FlutterPlugin, MethodCallHandler {
/// 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
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
private static MethodChannel channel;
private static Handler handler;
private static String message;
private static boolean isInit = false;
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "flutter_jpush_vip");
channel.setMethodCallHandler(this);
handler = new Handler(flutterPluginBinding.getApplicationContext());
}
// This static function is optional and equivalent to onAttachedToEngine. It supports the old
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
// 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);
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();
}
......@@ -50,4 +77,30 @@ public class FlutterJpushVipPlugin implements FlutterPlugin, MethodCallHandler {
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;
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.ups.JPushUPSManager;
import cn.jpush.android.ups.TokenResult;
import cn.jpush.android.ups.UPSRegisterCallBack;
public class Handler {
private Context context;
......@@ -11,16 +18,62 @@ public class Handler {
this.context = context;
}
public void init() {
JPushInterface.init(context);
public void init(UPSRegisterCallBack callBack) {
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() {
JPushInterface.setDebugMode(true);
}
/**
* 获取注册ID
*
* @return
*/
public String getRegistrationID() {
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;
import android.content.Intent;
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.service.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) {
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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
abortOnError false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.xiaoxiongyhh"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
......@@ -45,16 +53,37 @@ android {
JPUSH_CHANNEL: "00186a85d6e044ecce1406a8", //暂时填写默认值即可.
XIAOMI_APPKEY : "MI-5651762211854", // 小米平台注册的appkey
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 {
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.
// 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"
xmlns:tools="http://schemas.android.com/tools"
package="com.qiaomeng.flutter.flutter_jpush_vip_example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
......@@ -7,24 +8,26 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:debuggable="true"
android:icon="@mipmap/ic_launcher"
android:label="flutter_jpush_vip_example"
android:icon="@mipmap/ic_launcher">
tools:ignore="HardcodedDebugMode"
tools:replace="android:label">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:exported="true">
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
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
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
......@@ -32,11 +35,15 @@
Flutter's first frame. -->
<meta-data
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>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="com.example.jpushdemo.OpenClickActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
......@@ -44,15 +51,13 @@
<meta-data
android:name="flutterEmbedding"
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>
</manifest>
......@@ -7,130 +7,49 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
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.JSONObject;
import cn.jpush.android.api.JPushInterface;
import io.flutter.Log;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
Handler handler = new Handler(this);
private static final String TAG = "OpenClickActivity";
/**消息Id**/
/**
* 消息Id
**/
private static final String KEY_MSGID = "msg_id";
/**该通知的下发通道**/
/**
* 该通知的下发通道
**/
private static final String KEY_WHICH_PUSH_SDK = "rom_type";
/**通知标题**/
/**
* 通知标题
**/
private static final String KEY_TITLE = "n_title";
/**通知内容**/
/**
* 通知内容
**/
private static final String KEY_CONTENT = "n_content";
/**通知附加字段**/
/**
* 通知附加字段
**/
private static final String KEY_EXTRAS = "n_extras";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler.debug();
handler.init();
// handleOpenClick();
FlutterJpushVipPlugin.onNewIntent(getIntent());
}
@Override
protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent);
System.out.println("========================"+intent.getExtras());
}
/**
* 处理点击事件,当前启动配置的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();
FlutterJpushVipPlugin.onNewIntent(intent);
}
//获取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 {
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
}
// 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 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;
FlutterJpushVip.init().then((value) {
print("============$value");
});
FlutterJpushVip.onNotification((n){
print("============$n");
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
......@@ -50,10 +36,10 @@ class _MyAppState extends State<MyApp> {
),
body: GestureDetector(
onTap: () {
initPlatformState();
},
child: Center(
child: Text('Running on: $_platformVersion\n'),
child: Text('Running on: test'),
)),
),
);
......
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
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:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.1"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
charcode:
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: charcode
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.3"
collection:
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: collection
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.12"
convert:
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: convert
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
crypto:
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: crypto
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
description:
......@@ -64,6 +50,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: "direct main"
description: flutter
......@@ -95,41 +88,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.6"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
version: "1.8.0-nullsafety.1"
platform:
dependency: transitive
description:
......@@ -144,13 +123,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
......@@ -162,42 +134,42 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.3"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.15"
version: "0.2.19-nullsafety.2"
timezone:
dependency: transitive
description:
......@@ -211,21 +183,14 @@ packages:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.6.1"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5"
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
......@@ -6,8 +7,51 @@ class FlutterJpushVip {
static const MethodChannel _channel =
const MethodChannel('flutter_jpush_vip');
static Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion');
return version;
static Future<Map> init() {
return _channel.invokeMethod('init');
}
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