(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. centOS6.6虚拟机启动后登陆界面无法显示

    1.图一和图二对比就很明显发现,我的登陆界面不见了(突然断电导致不正常关机,造成图形界面桌面崩溃) 2.解决方法:启动按Ctrl+Alt+f2切换进命令行界面,root账号进入,重新下载图形界面

  2. 《HTTP协议详解》读书笔记---请求篇之响应状态码

    在接收和解释请求消息后,服务器返回一个http响应消息.它也分为3个部分:状态行.消息报头.响应正文,格式如下: HTTP-VersionStatus-CodeReason-PhraseCRLF(CR ...

  3. phpstrom换行的一个小坑

    安装phpstrom后汉化会默认不是左边定格换行,而是会智能换行 苦找了许久了,终于知道在哪设置了,跟大家分享一下,希望不要走同样的坑 不勾选即可

  4. Zabbix整合MegaCLI实现物理硬盘的自动发现和监控

    MegaCLI是LSI提供的用户空间管理RAID卡(LSI芯片)工具,适用于大多数的Dell服务器. MegaCLI介绍: http://zh.community.dell.com/techcente ...

  5. BZOJ3720 Gty的妹子树 【树分块】

    题目 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕-- Gty神(xian)犇(chong)从来不缺妹子-- 他来到了一棵妹子树下,发现每个妹子有一个美丽度 ...

  6. BZOJ1396&2865 识别子串 【后缀自动机 + 线段树】

    题目 输入格式 一行,一个由小写字母组成的字符串S,长度不超过10^5 输出格式 L行,每行一个整数,第i行的数据表示关于S的第i个元素的最短识别子串有多长. 输入样例 agoodcookcooksg ...

  7. java拼接字符串用StringBuilder

    StringBuilder builder = new StringBuilder(); String s1="abc"; for(int i=0;i<10000000;i+ ...

  8. PE508

    真是日了苟了我之前还以为那个递归会炸状态..我真他妈胆小啊.. = = 明确一下,这个可以构成所有高斯整数(唯一),构造方法大概就是先看曼哈顿距离,然后判断要不要减1,然后再/(1-i) 我们考虑在末 ...

  9. Python之数据结构:字符串中的方法

    一.过滤字符串 1.strip() (1)去掉行收尾不可见字符 a = ' wejifrow ' print a print a.strip() 结果: wejifrow wejifrow (2)st ...

  10. ZOJ1608 Two Circles and a Rectangle

    Time Limit: 2 Seconds      Memory Limit: 65536 KB Give you two circles and a rectangle, your task is ...