(1)搜索 https://pub.dartlang.org/packages/jpush_flutter ,安装插件,并且按照官方配置 /android/app/build.gradle

android: {
....
defaultConfig {
applicationId "替换成自己应用 ID"
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64' // 'arm64-v8a',
} manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}

(2)Flutter 新建页面,我放在Welcome页面

class SplashPageState extends State<SplashPage> implements OnSkipClickListener {
  JPush jPush = new JPush();
  String registerId;
  _startupJpush() {
    jPush.setup(appKey: "c52495cbcbc37ee42f04e751", channel: "developer-default",debug: true);
  }

  _getRegisterID() async {
    registerId = await jPush.getRegistrationID();
    print('*********registerid=' + registerId);
    return registerId;
  }

  _setPushTag() {
    List<String> tags = List<String>();
    tags.add("jason");
    jPush.setTags(tags);
  }

  _addEventHandler() {
    // Future<dynamic>event;
    jPush.addEventHandler(onReceiveNotification: (Map<String, dynamic> event) {
      print('*********addOnreceive>>>>>>$event');//进程运行时候可以接受
      var title = event['alert'];
      var extra = json.decode(event['extras']['cn.jpush.android.EXTRA']);
      notifyRoute(extra['type'],title,extra['id']);
      print('*********msg:$event');
    }, onOpenNotification: (Map<String, dynamic> event) {
      print('*********addOpenNoti>>>>>$event'); //进程关闭的时候可以接受
      var title = event['alert'];
      var extra = json.decode(event['extras']['cn.jpush.android.EXTRA']);
      notifyRoute(extra['type'],title,extra['id']);
    }, onReceiveMessage: (Map<String, dynamic> event) {
      print('*********addReceiveMsg>>>>>$event'); //进程运行时候可以接受
      print(event.toString());
      var jsStr = json.decode(event.toString());
    });
}

//推送跳转
void notifyRoute(String type,String title,String id) {
  if(type!=null) {
    switch(type){
    case 'news':
      Navigator.of(context).push(new MaterialPageRoute(builder: (ctx) => new WebView(title: title, url:id )));
      break;
    case 'tmdetail':
      Navigator.of(context).push(new MaterialPageRoute(builder: (ctx) => new DetailPage(tmId: int.parse(id))));
      break;
  }
  }
}

@override
void initState() {
// TODO: implement initState
  super.initState();
  _startupJpush();
  _setPushTag();
  _addEventHandler();
  _getRegisterID();
  _getWelcomeImage();
}
}

(3) 我的用是Extras 并且在客户端 通过参数 进行指定页面跳转

(4)服务端推送,C# Core版本 nuget搜索JiGuang.JPush

/// <summary>
/// 极光推送全局推送
/// </summary>
/// <param name="title">标题</param>
/// <param name="content">正文</param>
/// <param name="dic">extras字典</param>
/// <param name="indent">指定安卓页面,没用</param>
/// <param name="outmsg"></param>
/// <returns></returns>
public static bool Send(string title,string content, Dictionary<string,object> dic, Dictionary<string, object> indent,out string outmsg)
{
  var client = new Jiguang.JPush.JPushClient(appKey,appSecret);
  var android = new Android { Title = title, Alert = content, AlertType = 0, Extras = dic, Indent = indent };
  var ios = new IOS{ Alert= title, Extras= dic };
  var pushInfo = HD.DLL.Push.GetTopInfo();
  if(pushInfo!=null&&pushInfo.Id>0 )
  {
  var ts = System.DateTime.Now.Subtract(pushInfo.Addtime);
  if(ts.Hours<1)
  {
    outmsg = "最近的全局推送时间:"+pushInfo.Addtime+",请间隔一个小时";
    return false;
  }
  }
  var playLoad = new Jiguang.JPush.Model.PushPayload() {
    Platform = "all",
    //Audience = "all",
    Notification = new Notification() { Alert=title, Android =android,IOS=ios},
    Message = new Jiguang.JPush.Model.Message() { Content=content,Title=title,Extras= dic }
  };
  var response=client.SendPush(playLoad);
  outmsg = response.Content;
  var ret= response.StatusCode== System.Net.HttpStatusCode.OK;

  //记录推送日志
  pushInfo.Addtime = System.DateTime.Now;
  pushInfo.Title = title;
  pushInfo.Content = content;
  pushInfo.UserId = 0;
  pushInfo.Extras = JsonConvert.SerializeObject(dic);
  pushInfo.Status = ret ? 1 : -1;
  Push.Add(pushInfo);
  return ret;
}

 

 

Flutter接入极光推送的更多相关文章

  1. Flutter中极光推送的使用----jpush_flutter

    原文地址:https://www.cnblogs.com/niceyoo/p/11095994.html 1.申请极光账号和建立应用 极光推送的官方网址为:https://www.jiguang.cn ...

  2. java接入极光推送

    直接提供工具类, 调用时直接调用其 sendToRegistrationId() 方法 1 import cn.jiguang.common.resp.APIConnectionException; ...

  3. JPush Flutter Plugin(Futter推送-极光推送)

    https://pub.flutter-io.cn/packages/jpush_flutter JPush's officially supported Flutter plugin (Androi ...

  4. 极光推送_总结_01_Java实现极光推送

    一.代码实现 1.配置类—Env.java package com.ray.jpush.config; /**@desc : 极光推送接入配置 * * @author: shirayner * @da ...

  5. 【Android应用开发】 推送原理解析 极光推送使用详解 (零基础精通推送)

    作者 : octopus_truth 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/45046283 推送技术产生场景 : -- ...

  6. JPushDemo【极光推送集成,基于v3.1.8版本】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这个Demo只是记录极光推送的集成,不能运行. 使用步骤 一.项目组织结构图 注意事项: 1.  导入类文件后需要change包名以 ...

  7. 68-Flutter中极光推送的使用

    1.申请极光账号和建立应用 极光推送的官方网址为:https://www.jiguang.cn/ 注册好后,进入'服务中心',然后再进入'开发者平台',点击创建应用. 这时候会出现新页面,让你填写“应 ...

  8. 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言

    在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...

  9. 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)

    这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...

随机推荐

  1. Android简单的BaseExpandableList使用

    1.Activity package com.example.administrator.mystudent.ExpandableListView; import android.app.Expand ...

  2. 基于 <tx> 和 <aop> 命名空间的声明式事务管理

    环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加方法: 点击项目右键->Build Path->Add ...

  3. 使用SS5搭建linux下的sock5代理服务器

    http://sourceforge.net/projects/ss5/下载最新源码 apt-get install libpam0g-dev apt-get install libldap2-dev ...

  4. hihoCoder [Offer收割]编程练习赛83 D 生成树问题

    题目 从 Kruskal 算法的角度来思考这个问题. 考虑 $n$ 个点的"空图"(即没有边的图). 先将 $m_2$ 条无权值的边加到图中,得到一个森林. 按边权从小到大的顺序枚 ...

  5. SELECT中的CAST

    SELECT CAST a.b AS int 语法意义 把表别名A的B列的数据类型变为INT

  6. 移动端px转rem的两种方法

    rem使用方法: rem ,root element,即相对于根元素的大小,浏览器默认字符大小为16px,此时1rem相当于16px.  方法1 设置font-size: body{font-size ...

  7. 微信小程序 报警告的解决办法

    wx:for   如果没有给它相应的  wx:key 控制台就会有警告,解决的办法给它添加相应的key警告就消失啦

  8. POJ3170 Bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士

    1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 281  Solved: 180 ...

  9. VijosP1303 导弹拦截

    背景 实中编程者联盟为了培养技术精湛的后备人才,必须从基础题开始训练. 描述 某国为了防御敌国的导弹袭击,研发出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度, ...

  10. yoga安装kali备忘(连接wifi)

    kali 2.0 iso win8 下安装 用 WinSetupFromUSB-1-6-beta2 写入u盘,正常安装系统 启动连接wifi 搜索信号,获取ssid iw wlan0 scan 查看是 ...