(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. Leetcode 640.求解方程

    求解方程 求解一个给定的方程,将x以字符串"x=#value"的形式返回.该方程仅包含'+',' - '操作,变量 x 和其对应系数. 如果方程没有解,请返回"No so ...

  2. 使用 宝塔面板快速部署Java项目

    环境描述: 服务器系统:CentOS7 64位操作系统 面板版本:宝塔6.9.4 Nginx版本:Nginx 1.16 Tomcat版本:Tomcat7 JDK版本:1.8.0_121 环境部署就不用 ...

  3. JVM虚拟机系列(一)类的加载

    JAVA虚拟机系列(一) 类的加载 目录 1 类的初始化过程 2 详解初始化时的各个阶段 一.类初始化的过程 先来看一个CLASS文件在整体生命周期里会遇到的阶段: xxxx.class ---> ...

  4. 优化脚本性能 Optimizing Script Performance

    This page gives some general hints for improving script performance on iOS. 此页面提供了一些一般的技巧,提高了在iOS上的脚 ...

  5. 【转】C# client 与java netty 服务端的简单通信,客户端采用Unity

    http://blog.csdn.net/wilsonke/article/details/24721057 近日根据官方提供的通信例子自己写了一个关于Unity(C#)和后台通信的类,拿出来和大家分 ...

  6. setTimeOut传参数

    最近,因项目需要,需要实现setTimeOut传参数的功能,搜索了很多的资源.终于找到一个比较好的方法了,记录下来,与大家分享. 无论是window.setTimeOut还是window.setInt ...

  7. BootStrap导入及其使用

    BootStrap主要是一个CSS框架,用于页面布局 <!DOCTYPE html> <html lang="en"> <head> <m ...

  8. iOS-字体UIFont的lineHeight与pointSize

    首先我们来看一看UIFont的API里面有哪些属性: // Font attributes @property(nonatomic,readonly,strong) NSString *familyN ...

  9. libcmt.lib和msvcrt.lib冲突,原因和解决方法

    libcmt.lib和msvcrt.lib冲突,原因和解决方法 https://blog.csdn.net/longlijun/article/details/7331093 libcmt.lib是w ...

  10. vim configure

    vim configure .vimrc " An example for a vimrc file. " " Maintainer: Bram Moolenaar &l ...