在Android中使用reactnative集成极光推送步骤如下:

(1)在AndroidManifest中声明网络权限,获取包名到极光推送官网添加应用,获取AppKey,该key需要注册到应用中以获取推送消息

再添加这个权限

android:protectionLevel="signature"/>

AndroidManifest

官网获取AppKey

(2)在AS中的Terminal终端分别敲入以下命令行

npm install jcore-react-native --save

npm install jpush-react-native --save

(3)配置

1、在settings.gradle文件添加以下代码

include':jpush-react-native',':jcore-react-native'

project(':jpush-react-native').projectDir =new File(rootProject.projectDir,'../node_modules/jpush-react-native/android')

project(':jcore-react-native').projectDir =new File(rootProject.projectDir,'../node_modules/jcore-react-native/android')

2、在build.gradle(app)中添加

manifestPlaceholders = [

JPUSH_APPKEY:"",//在此替换你的APPKey

APP_CHANNEL:"developer-default"//应用渠道号

]

添加JPUSH_APPKEY

再添加依赖文件

dependencies {

compile fileTree(dir: "libs", include: ["*.jar"])

compile project(':jpush-react-native')

compile project(':jcore-react-native')

}

这样就可以sync,可以看到项目工程下有这两个文件了

极光推送依赖库

(4)在AndroidManifest添加以下代码。

android:value="${APP_CHANNEL}"/>

android:value="${JPUSH_APPKEY}"/>

声明JUPSH参数

(5)在MainApplication.java中声明JPushPackage

声明JPushPackage模块

至此,AndroidStudio端的配置搞定了,接下来就是RN的代码初始化。

(6)在你reactnative的入口代码处引入库

简单例子:

import JPushModule from'jpush-react-native'

初始化极光推送,判断平台是否为安卓

if(global.ANDROID) {

//android

JPushModule.initPush()

//获取客户端的registrationId,通过这个id可以由官网推送消息

JPushModule.getRegistrationID((registrationId) => {

console.log("registrationId:"+ registrationId);

});

}else{

}

demo例子代码如下:

'use strict';

import React from 'react';

import ReactNative from 'react-native';

const {

Text,

View,

TextInput,

TouchableHighlight,

PropTypes,

requireNativeComponent,

NativeModules,

ScrollView,

StyleSheet,

DeviceEventEmitter,

} = ReactNative;

import JPushModule from 'jpush-react-native';

const receiveCustomMsgEvent = "receivePushMsg";

const receiveNotificationEvent = "receiveNotification";

const openNotificationEvent = "openNotification";

const getRegistrationIdEvent = "getRegistrationId";

export default class PushActivity extends React.Component {

constructor(props) {

super(props);

this.state = {

bg: '#ffffff',

appkey: 'AppKey',

imei: 'IMEI',

package: 'PackageName',

deviceId: 'DeviceId',

version: 'Version',

pushMsg: 'PushMessage',

registrationId: 'registrationId',

};

this.jumpSetActivity = this.jumpSetActivity.bind(this);

this.onInitPress = this.onInitPress.bind(this);

this.onStopPress = this.onStopPress.bind(this);

this.onResumePress = this.onResumePress.bind(this);

this.onGetRegistrationIdPress = this.onGetRegistrationIdPress.bind(this);

this.jumpSecondActivity = this.jumpSecondActivity.bind(this);

}

jumpSetActivity() {

this.props.navigation.navigate("Setting");

}

jumpSecondActivity() {

console.log("jump to SecondActivity");

// JPushModule.jumpToPushActivityWithParams("SecondActivity", {

// hello: "world"

// });

this.props.navigation.navigate("Push");

}

onInitPress() {

JPushModule.initPush();

}

onStopPress() {

JPushModule.stopPush();

console.log("Stop push press");

}

onResumePress() {

JPushModule.resumePush();

console.log("Resume push press");

}

onGetRegistrationIdPress() {

JPushModule.getRegistrationID((registrationId) => {

this.setState({

registrationId: registrationId

});

console.log(this.state.registrationId);

});

}

componentWillMount() {}

componentDidMount() {

JPushModule.getInfo((map) => {

this.setState({

appkey: map.myAppKey,

imei: map.myImei,

package: map.myPackageName,

deviceId: map.myDeviceId,

version: map.myVersion

});

});

JPushModule.notifyJSDidLoad((resultCode) => {

if (resultCode === 0) {}

});

JPushModule.addReceiveCustomMsgListener((map) => {

this.setState({

pushMsg: map.message

});

console.log("extras: " + map.extras);

});

JPushModule.addReceiveNotificationListener((map) => {

console.log("alertContent: " + map.alertContent);

console.log("extras: " + map.extras);

// var extra = JSON.parse(map.extras);

// console.log(extra.key + ": " + extra.value);

});

JPushModule.addReceiveOpenNotificationListener((map) => {

console.log("Opening notification!");

console.log("map.extra: " + map.extras);

this.jumpSecondActivity();

// JPushModule.jumpToPushActivity("SecondActivity");

});

JPushModule.addGetRegistrationIdListener((registrationId) => {

console.log("Device register succeed, registrationId " + registrationId);

});

}

componentWillUnmount() {

JPushModule.removeReceiveCustomMsgListener(receiveCustomMsgEvent);

JPushModule.removeReceiveNotificationListener(receiveNotificationEvent);

JPushModule.removeReceiveOpenNotificationListener(openNotificationEvent);

JPushModule.removeGetRegistrationIdListener(getRegistrationIdEvent);

console.log("Will clear all notifications");

JPushModule.clearAllNotifications();

}

render() {

return (

{ this.state.appkey }

{ this.state.imei }

{ this.state.package }

{ this.state.deviceId }

{ this.state.version }

underlayColor='#0866d9'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.jumpSetActivity }>

设置

underlayColor='#0866d9'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.onInitPress }>

INITPUSH

underlayColor='#e4083f'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.onStopPress }>

STOPPUSH

underlayColor='#f5a402'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.onResumePress }>

RESUMEPUSH

underlayColor='#f5a402'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.onGetRegistrationIdPress }>

GET REGISTRATIONID

underlayColor='#f5a402'

activeOpacity={ 0.5 }

style={ styles.btnStyle }

onPress={ this.jumpSecondActivity }>

Go to SecondActivity

{ this.state.pushMsg }

{ this.state.registrationId }

)

}

}

var styles = StyleSheet.create({

parent: {

backgroundColor: '#f0f1f3'

},

textStyle: {

marginTop: 10,

textAlign: 'center',

fontSize: 20,

color: '#808080'

},

btnStyle: {

marginTop: 10,

borderWidth: 1,

borderColor: '#3e83d7',

borderRadius: 8,

backgroundColor: '#3e83d7'

},

btnTextStyle: {

textAlign: 'center',

fontSize: 25,

color: '#ffffff'

},

inputStyle: {

borderColor: '#48bbec',

borderWidth: 1,

},

});

至此配置结束,可以到官网进行消息推送。

相关链接

极光推送 简书android,(Android)react-native集成极光推送相关推荐

  1. React Native集成极光推送

    推送作为手机应用的基本功能,是手机应用的重要部分,如果自己实现一套推送系统费时费力,所以大部分的应用都会选择使用第三方的推送服务,如极光推送.下面就以React Native项目集成jpush-rea ...

  2. android中设置lmargin简书,超详细React Native实现微信好友/朋友圈分享功能-Android/iOS双平台通用...

    (一)前言 本文主要会涉及到以下内容: 微信开发者应用申请审核 安装配置微信分享库 微信好友/朋友圈功能实现 (二)应用申请审核 首先大家需要去微信开发平台去注册账号并且创建一个移动应用.(地址:ht ...

  3. React Native 集成极光推送 jpush-react-native

    转载:https://www.jianshu.com/p/a71512a8f921 概述 jpush-react-native 是极光推送官方开发的 React Native 版本插件,可以快速集成推 ...

  4. React Native集成极光消息推送

    极光IOS消息推送证书一键生成地址:https://onesignal.com/provisionator 一.申请激光账号并创建应用:地址:https://www.jiguang.cn 二.IOS推 ...

  5. React Native集成友盟推送

    React Native集成友盟推送 android推送集成 1.导入SDK: (1)push文件夹位置: (2)将push文件夹直接复制粘贴到rn项目android目录下,目录结构如下: 2.添加修 ...

  6. 从 Android 到 React Native 开发(四、打包流程解析和发布为 Maven 库 )

    1.从 Android 到 React Native 开发(一.入门) 2.从 Android 到 React Native 开发(二.通信与模块实现) 3.从 Android 到 React Nat ...

  7. React Native 集成分享第三方登录功能分享第三方登录模块开发(iOS)

    期待已久的新课上线啦!解锁React Native开发新姿势,一网打尽React Native最新与最热技术,点我Get!!! 在我们常用的App中经常会看到分享与第三方登录的功能,可以说分享与第三方 ...

  8. 跨平台应用开发进阶(八) :uni-app 实现Android原生APP-云打包集成极光推送(JG-JPUSH)详细教程

    文章目录 一.前言 二.资源 三.集成 3.1 SDK 引入 3.2 代码集成 3.3 遇到的问题及解决方案 3.3.1 包大小限制 3.3.2 [JS Framework] 当前运行的基座不包含原生 ...

  9. android 仿简书评论,Android 开发仿简书登录框可删除内容或显示密码框的内容

    简书App 是我很喜欢的一款软件.今天就模仿了一下他的登录框.先上图: 好了下面上代码,自定义ImgEditText 继承与EditText.重写一些方法. package lyf.myimgedit ...

最新文章

  1. 手摸手入门前端--01.webpack4
  2. 【Linux】IPC-消息队列
  3. java安全——加密
  4. StringBuffer的存在的含义
  5. image 闪烁 c# ajax updatepanel,Why doesn't asp:UpdatePanel refresh an Image?
  6. 创意购物海报|吸引你的不止买买买,更是创意!
  7. sql server 监视_如何在SQL Server中监视对象空间增长
  8. Leetcode c语言-Divide Two Integers
  9. 奇异的Pinvoke调用
  10. 笔记本电脑不要锁定计算机,笔记本电脑键盘怎么解锁呢
  11. 数学分析教程(科大)——1.3笔记+习题
  12. 价格操控:大数据“杀熟”和算法合谋
  13. 苹果真伪查询_二手MacBook Pro Air等苹果笔记本验货 鉴定 基本方法 流程
  14. 华为3Com总裁郑树生:我们最终要自立门户
  15. CSS3画三角形、菱形、平行四边形
  16. 个人股权能转让给别人吗
  17. Arduino与Proteus仿真实例-74LS378触发器驱动仿真
  18. 计算机应用专业可以考哪些证,计算机应用技术专业学生需要考取哪些证书?
  19. 「LibreOJ NOI Round #2」单枪匹马
  20. Google Cloud 线上课堂 | Kubernetes 网络演进,GKE Gateway API 打开新篇章

热门文章

  1. 2019.03.17 14:58
  2. mediawiki 编辑php代码,mediawiki_1.25配置wikieditor编辑器
  3. 两条信号之间加电容_模电总结:第七章、波形的发生和信号的转换,正弦波振荡的电路...
  4. 越狱后必装软件_iOS 13全系统越狱详细教程疑难解答
  5. 后端怎么接收map_史上最全,C++后端开发面试题与知识点汇总
  6. Java中,与;||与|的区别
  7. adb shell常用命令收录
  8. 内温的整体优先效应实验_[心理学复习.doc
  9. 计算机汉字的输入和编辑教案,计算机汉字录入教案
  10. 搭建fastdfs集群