1.极光平台创建应用
2.推送设置配置包名
- pubspec.yaml文件夹添加
# 极光推送
jpush_flutter: 0.5.5
别忘记Pub get
4.配置
\android\app\build.gradle下添加
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,//包名
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
5.main.dart
final JPush jpush = new JPush();
jpush.setup(
appKey: "b79e9fbb2198dd16b92eff88",
channel: "flutter_channel",
production: false,
debug: true, //是否打印debug日志
);
6.监听推送操作事件
// 接收通知回调方法。
void _getmsg() {
jpush.addEventHandler(
// 接收通知消息
onReceiveMessage: (Map<String, dynamic> message) async {
print("监听的信息==》${message}");
}, // 点击通知回调方法。
onOpenNotification: (Map <String, dynamic> message) async {
print("点击推送==》${message}");
print("内容==>${message['extras']['cn.jpush.android.ALERT']}");
print("title==>${message['title']}");
},
// 自定义消息
onReceiveNotification: (Map <String, dynamic> message) async {
print("自定义消息==》${message}");
print("内容==>${message['extras']['cn.jpush.android.ALERT']}");
print("title==>${message['title']}");
},
);
}