Android
安卓端配置文档地址
核心示例代码:
// iOS/安卓端外推送代码
const iosPushConfig = {
tokenName: 'push_online',
};
const androidPushConfig = {
xmAppId: '2882303761517806219',
xmAppKey: '5971780672219',
xmCertificateName: 'RN_MI_PUSH',
hwCertificateName: 'RN_HW_PUSH',
mzAppId: '113798',
mzAppKey: 'b74148973e6040c6abbda2af4c2f6779',
mzCertificateName: 'RN_MZ_PUSH',
fcmCertificateName: 'RN_FCM_PUSH',
vivoCertificateName: "vivo证书名",
oppoAppId: "xxx", // oppoAppId, oppoAppKey, oppoAppSercet 在oppo推送平台注册得到
oppoAppKey: "xxx",
oppoAppSercet: "xxx",
oppoCertificateName: "oppo证书名"
};
var nim = SDK.NIM.getInstance({
// ...
iosPushConfig,
androidPushConfig,
// ...
})
// 安卓端内推送示例代码
import { showNotification } from '../nim/NIM_Android_Push';
showNotification({
icon: '', title: msg.from, content: showText, time: `${msg.time}`,
});
其中各个平台的 certificateName 是在网易云信后台添加的证书名称:
示例如下图:
网易云信后台访问地址
网易云信安卓端各大厂商推送配置文档:
安卓端各个平台推送是建立在app审核通过后,推送是需要额外配置开启功能的,厂商推送是为了在杀掉进程时由厂商发起推送,如果只是切换到后台时接到消息通知,不需要接厂商推送
Android 手动配置
手动link
请在 app gradle 文件 dependencies 添加此模块。
将
nimpush
文件夹拷贝到android
文件夹下android/setting.gradle
// 添加
include ':nimpush'
android/app/build.gradle
dependencies {
// 添加
implementation project(':nimpush')
}
android/app/src/main/java/com/app/MainApplication.java
// 添加
import com.netease.nim.rn.push.NIMPushPackage;
// ...
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
// ...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// ...
new MainReactPackage(),
new RealmReactPackage(),
// 添加
new NIMPushPackage()
);
}
android/app/src/AndroidManifest.xml 配置
权限部分
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
小米推送
自定义权限
<permission
android:name="你的应用包名.permission.MIPUSH_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="你的应用包名.permission.MIPUSH_RECEIVE" />
推送服务和广播
<service
android:name="com.xiaomi.push.service.XMJobService"
android:enabled="true"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
android:process=":mixpush" />
<service
android:name="com.xiaomi.push.service.XMPushService"
android:enabled="true"
android:process=":mixpush" />
<receiver
android:name="com.xiaomi.push.service.receivers.PingReceiver"
android:exported="false"
android:process=":mixpush">
<intent-filter>
<action android:name="com.xiaomi.push.PING_TIMER" />
</intent-filter>
</receiver>
<receiver
android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name="com.xiaomi.mipush.sdk.PushMessageHandler"
android:enabled="true"
android:exported="true" />
<service
android:name="com.xiaomi.mipush.sdk.MessageHandleService"
android:enabled="true" />
<receiver
android:name="com.netease.nimlib.mixpush.mi.MiPushReceiver"
android:exported="true">
<intent-filter android:priority="0x7fffffff">
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
<action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" />
<action android:name="com.xiaomi.mipush.ERROR" />
</intent-filter>
</receiver>
其他推送配置参照 android/nimpush/readme.md 文件配置
文档更新时间: 2021-08-03 09:57