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

添加文档说明

parent 790d83cd
......@@ -2,13 +2,98 @@
极光推送厂商版
## Getting Started
## android篇
现android仅集成了小米,oppo,华为,vivo厂商
This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
1. 主module build.gradle 配置
```
android {
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
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
public class MainActivity extends FlutterActivity {
@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 @@
</intent-filter>
</service>
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="${HUAWEI_APPID}" />
</application>
</manifest>
......@@ -48,9 +48,9 @@ android {
versionName flutterVersionName
manifestPlaceholders = [
JPUSH_PKGNAME: "com.xiaoxiongyhh",
JPUSH_PKGNAME : "com.xiaoxiongyhh",
JPUSH_APPKEY : "07df3009b7469ad95427b4f7", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL: "00186a85d6e044ecce1406a8", //暂时填写默认值即可.
JPUSH_CHANNEL : "00186a85d6e044ecce1406a8", //暂时填写默认值即可.
XIAOMI_APPKEY : "MI-5651762211854", // 小米平台注册的appkey
XIAOMI_APPID : "MI-2882303761517622854", // 小米平台注册的appid
OPPO_APPKEY : "OP-cWtlupo7k6goCWGs8kCcoGw44", // OPPO平台注册的appkey
......@@ -58,7 +58,7 @@ android {
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", // 华为
HUAWEI_APPID : "100103671", // 华为
]
......@@ -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 @@
<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" />
</application>
......
......@@ -2,40 +2,15 @@ package com.qiaomeng.flutter.flutter_jpush_vip_example;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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;
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
protected void onCreate(@Nullable Bundle savedInstanceState) {
......
......@@ -6,48 +6,63 @@ import 'package:flutter/services.dart';
class FlutterJpushVip {
static const MethodChannel _channel =
const MethodChannel('flutter_jpush_vip');
static Future<Map> init() {
return _channel.invokeMethod('init');
/// 初始化
static Future<_InitResult> init() async {
var map = await _channel.invokeMethod('init');
return _InitResult.from(map);
}
/// 开启调试模式
static void debug() {
_channel.invokeMethod('debug');
}
/// 获取注册ID
static Future<String> getRegistrationID() {
return _channel.invokeMethod('getRegistrationID');
}
/// 清除通知
static void clearAllNotifications() {
_channel.invokeMethod('clearAllNotifications');
}
static void onNotification(Function(Notification notification) callback) {
/// 监听通知
static void onNotification(Function(_Notification notification) callback) {
_channel.setMethodCallHandler((call) {
if (call.method == '__JPUSH_MESSAGE__') {
try {
Map map = json.decode(call.arguments);
var n = Notification.from(map);
var n = _Notification.from(map);
callback(n);
} catch (e) {
print(e);
}
}
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 content;
String title;
Map extras;
int platform;
String platform;
Notification.from(Map map) {
msgId = map['msg_id'];
_Notification.from(Map map) {
msgId = map['msg_id'].toString();
content = map['n_content'];
title = map['n_title'];
extras = map['n_extras'];
platform = map['rom_type'];
platform = map['rom_type'].toString();
}
@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