Commit 81d767e8 authored by 李增强's avatar 李增强

添加文档说明

parent 790d83cd
...@@ -2,13 +2,98 @@ ...@@ -2,13 +2,98 @@
极光推送厂商版 极光推送厂商版
## Getting Started ## android篇
现android仅集成了小米,oppo,华为,vivo厂商
This project is a starting point for a Flutter 1. 主module build.gradle 配置
[plug-in package](https://flutter.dev/developing-packages/), ```
a specialized package that includes platform-specific implementation code for android {
Android and/or iOS. defaultConfig {
manifestPlaceholders = [
JPUSH_PKGNAME : "注册报名",
JPUSH_APPKEY : "JPush 上注册的包名对应的 Appkey",
JPUSH_CHANNEL : "暂时填写默认值即可",
XIAOMI_APPKEY : "MI-小米平台注册的appkey",
XIAOMI_APPID : "MI-小米平台注册的appid",
OPPO_APPKEY : "OP-OPPO平台注册的appkey",
OPPO_APPID : "OP-OPPO平台注册的appid",
OPPO_APPSECRET: "OP-OPPO平台注册的appsecret",
VIVO_APPKEY : "VIVO平台注册的appkey",
VIVO_APPID : "VIVO平台注册的appid",
HUAWEI_APPID : "华为注册的appid",
]
}
}
```
2. 在被调起的activity处理消息
```
// 在AndroidManifest.xml配置Activity android:exported="true", 如果activity是首页又不想多次启动可以设置android:launchMode="singleTask"
For help getting started with Flutter, view our public class MainActivity extends FlutterActivity {
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference. @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
com.qiaomeng.flutter.flutter_jpush_vip.FlutterJpushVipPlugin.FlutterJpushVipPlugin.onNewIntent(getIntent());
}
@Override
protected void onNewIntent(@NonNull Intent intent) {
super.onNewIntent(intent);
com.qiaomeng.flutter.flutter_jpush_vip.FlutterJpushVipPlugin.FlutterJpushVipPlugin.onNewIntent(intent);
}
}
```
3. 厂商推送时
小米不需要带uri_activity
oppo 需要带 uri_action
华为 需要带uri_activity
vivo 需要带uri_activity
# api
```
import 'package:flutter_jpush_vip/flutter_jpush_vip.dart';
// 初始化
FlutterJpushVip.init().then((_InitResult value) {
});
// 监听点击了通知
FlutterJpushVip.onNotification((_Notification n){
});
// 获取注册ID,需要再init后才能获取
String registrationId = await FlutterJpushVip.getRegistrationID();
// 清除通知
FlutterJpushVip.clearAllNotifications();
// 开启调试模式
FlutterJpushVip.debug();
class _InitResult {
int code; // 状态码,0标识初始化成功
String registrationId; // 注册ID
}
class _Notification {
String msgId; // 消息ID
String content; // 消息内容
String title; // 消息标题
Map extras; // 携带参数
String platform; // 推送平台, 0为极光,1为小米,2为华为,3为魅族,4为oppo,5为vivo,8为FCM
}
```
\ No newline at end of file
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
</intent-filter> </intent-filter>
</service> </service>
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="${HUAWEI_APPID}" />
</application> </application>
</manifest> </manifest>
...@@ -48,17 +48,17 @@ android { ...@@ -48,17 +48,17 @@ android {
versionName flutterVersionName versionName flutterVersionName
manifestPlaceholders = [ manifestPlaceholders = [
JPUSH_PKGNAME: "com.xiaoxiongyhh", JPUSH_PKGNAME : "com.xiaoxiongyhh",
JPUSH_APPKEY : "07df3009b7469ad95427b4f7", //JPush 上注册的包名对应的 Appkey. JPUSH_APPKEY : "07df3009b7469ad95427b4f7", //JPush 上注册的包名对应的 Appkey.
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_APPKEY : "OP-cWtlupo7k6goCWGs8kCcoGw44", // OPPO平台注册的appkey
OPPO_APPID : "OP-3597314", // OPPO平台注册的appid OPPO_APPID : "OP-3597314", // OPPO平台注册的appid
OPPO_APPSECRET: "OP-6d91f494e2C8752910cEd15571Af8893", //OPPO平台注册的appsecret OPPO_APPSECRET: "OP-6d91f494e2C8752910cEd15571Af8893", //OPPO平台注册的appsecret
VIVO_APPKEY : "c88ba5d2-38f7-4286-b512-3bcd5834f3c1", // VIVO平台注册的appkey VIVO_APPKEY : "c88ba5d2-38f7-4286-b512-3bcd5834f3c1", // VIVO平台注册的appkey
VIVO_APPID : "16048", // VIVO平台注册的appid VIVO_APPID : "16048", // VIVO平台注册的appid
"com.huawei.hms.client.appid": "appid=100103671", // 华为 HUAWEI_APPID : "100103671", // 华为
] ]
...@@ -76,16 +76,6 @@ android { ...@@ -76,16 +76,6 @@ android {
} }
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.release
}
}
} }
......
...@@ -51,12 +51,6 @@ ...@@ -51,12 +51,6 @@
<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" />
</application> </application>
......
...@@ -2,40 +2,15 @@ package com.qiaomeng.flutter.flutter_jpush_vip_example; ...@@ -2,40 +2,15 @@ package com.qiaomeng.flutter.flutter_jpush_vip_example;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
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.FlutterJpushVipPlugin; import com.qiaomeng.flutter.flutter_jpush_vip.FlutterJpushVipPlugin;
import org.json.JSONException;
import org.json.JSONObject;
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 {
/**
* 消息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 @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
......
...@@ -6,48 +6,63 @@ import 'package:flutter/services.dart'; ...@@ -6,48 +6,63 @@ import 'package:flutter/services.dart';
class FlutterJpushVip { class FlutterJpushVip {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('flutter_jpush_vip'); const MethodChannel('flutter_jpush_vip');
/// 初始化
static Future<Map> init() { static Future<_InitResult> init() async {
return _channel.invokeMethod('init'); var map = await _channel.invokeMethod('init');
return _InitResult.from(map);
} }
/// 开启调试模式
static void debug() { static void debug() {
_channel.invokeMethod('debug'); _channel.invokeMethod('debug');
} }
/// 获取注册ID
static Future<String> getRegistrationID() { static Future<String> getRegistrationID() {
return _channel.invokeMethod('getRegistrationID'); return _channel.invokeMethod('getRegistrationID');
} }
/// 清除通知
static void clearAllNotifications() { static void clearAllNotifications() {
_channel.invokeMethod('clearAllNotifications'); _channel.invokeMethod('clearAllNotifications');
} }
/// 监听通知
static void onNotification(Function(Notification notification) callback) { static void onNotification(Function(_Notification notification) callback) {
_channel.setMethodCallHandler((call) { _channel.setMethodCallHandler((call) {
if (call.method == '__JPUSH_MESSAGE__') { if (call.method == '__JPUSH_MESSAGE__') {
Map map = json.decode(call.arguments); try {
var n = Notification.from(map); Map map = json.decode(call.arguments);
callback(n); var n = _Notification.from(map);
callback(n);
} catch (e) {
print(e);
}
} }
return null; return null;
}); });
} }
} }
class Notification { class _InitResult {
int code;
String registrationId;
_InitResult.from(Map map) {
code = map['code'];
registrationId = map['registrationId'];
}
}
class _Notification {
String msgId; String msgId;
String content; String content;
String title; String title;
Map extras; Map extras;
int platform; String platform;
Notification.from(Map map) { _Notification.from(Map map) {
msgId = map['msg_id']; msgId = map['msg_id'].toString();
content = map['n_content']; content = map['n_content'];
title = map['n_title']; title = map['n_title'];
extras = map['n_extras']; extras = map['n_extras'];
platform = map['rom_type']; platform = map['rom_type'].toString();
} }
@override @override
......
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