一、配置极光开发者

1.注册极光开发者

https://www.jiguang.cn/push

2.创建应用

二、创建APP

1.添加依赖

pubspec.yaml  添加: flutter_jpush: ^0.0.4

2.android 专属配置

    defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "xxx"
minSdkVersion
targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64' // 'arm64-v8a',
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL : "developer-default",//你的推送渠道,如果不知道填写developer-default即可
]
}

3.编写代码

import 'package:flutter/material.dart';
import 'package:flutter_jpush/flutter_jpush.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
} class _MyAppState extends State<MyApp> { void initState(){
super.initState();
_initJPush();
_initNotification();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("测试"),
),
body: Center(
child: Text('data'),
)),
);
} //初始化
void _initJPush() async {
await FlutterJPush.startup();
print("初始化jpush成功"); // 获取 registrationID
var registrationID = await FlutterJPush.getRegistrationID();
print(registrationID); // 注册接收和打开 Notification()
_initNotification();
}
//初始化
void _initNotification() async {
FlutterJPush.addReceiveNotificationListener(
(JPushNotification notification) {
print("收到推送提醒: $notification");
}); FlutterJPush.addReceiveOpenNotificationListener(
(JPushNotification notification) {
print("打开了推送提醒: $notification");
});
}
}

测试

推送通知

注意:android一定要加上包名,而且一旦确认不能更改

最新文章

  1. Android 使用代码主动去调用控件的点击事件(模拟人手去触摸控件)
  2. js判断浏览器
  3. 初识Flask
  4. tcp_tw_recycle 的问题, 使用某一个wifi,APP老是连接不上网络
  5. Python 统计IIS日志行数
  6. PHP-Java-Bridge的使用(平安银行支付功能专版)
  7. Linq基本用法
  8. ubuntu下使用C语言开发一个cgi程序
  9. Linux驱动开发 -- 打开dev_dbg()
  10. 响应式、手机端、自适应 百分比实现div等宽等高的方法
  11. MySQL之删_delete-truncate
  12. httpClient closeableHttpClient
  13. 我应该如何在Pycharm中去运行别人的Django项目
  14. python的os模块fnmatch模块介绍
  15. OAuth2.0深入理解
  16. Python3根据基础概率随机生成选项
  17. LeetCode:105_Construct Binary Tree from Preorder and Inorder Traversal | 根据前序和中序遍历构建二叉树 | Medium
  18. JSP内置对象——Exception对象
  19. Win7 VS2015及MinGW环境编译FFMPEG-20160326
  20. JS遍历Table的所有单元格内容

热门文章

  1. 【python】python获取当前日期前后N天或N月的日期
  2. Spark探索经典数据集MovieLens
  3. POJ3261 Milk Patterns 【后缀数组】
  4. RTL2832U+R820T电视棒windows下安装sdr# 以及搭建ADS-B使用VirtualRadar看飞机的教程
  5. HDU 5665
  6. D. Relatively Prime Graph
  7. (转)HTTP请求中URL地址的编码和解码
  8. Codeforces Round #299 Div2 解题报告
  9. opencv_人脸检测、模型训练、人脸识别
  10. python3 yield表达式形式应用