uniPush

需要拷贝的文件

需要引入工程的jar/aar文件

需要将以下jar/aar文件放到工程的libs目录下

路径 文件
SDK\libs aps-release.aar, aps-unipush-release.aar, gtc-3.1.1.0.aar, gtsdk-3.2.0.0.aar, hwp-3.0.1.aar, mzp-3.0.2.aar, oppo-3.0.3.aar, vivo-3.0.3.aar, xmp-3.0.2.aar, push-3.0.0.aar(HBuilderX 3.3.13及以上), push-internal-4.1.4.aar(HBuilderX 3.3.13及以上)

gradle配置

打开build.gradle,在defaultConfig添加manifestPlaceholders节点,如下图所示,将io.dcloud.HBuilder替换成自己的应用包名,将appid等信息替换成申请之后的appid等。

应用的app id/app key等信息,从开发者后台->unipush->配置管理->应用管理 界面查看 注意:HBuilderX3.1.15之后需要添加GETUI_APPID属性

  1. android {
  2. defaultConfig {
  3. manifestPlaceholders = [
  4. "GETUI_APPID": "unipush的appid",
  5. "plus.unipush.appid" : "unipush的appid",
  6. "plus.unipush.appkey" : "unipush的key",
  7. "plus.unipush.appsecret": "unipush的secret",
  8. "apk.applicationId":"io.dcloud.HBuilder"
  9. ]
  10. }
  11. }

AndroidManifest.xml配置

在io.dcloud.PandoraEntry的Activity标签下追加intent-filter

  1. <intent-filter>
  2. <action android:name="android.intent.action.VIEW"/>
  3. <category android:name="android.intent.category.DEFAULT" />
  4. <category android:name="android.intent.category.BROWSABLE" />
  5. <data android:host="io.dcloud.unipush" android:path="/" android:scheme="unipush" />
  6. </intent-filter>

厂商配置

添加下列内容到androidmanifest.xml中(未申请平台无需添加)

  1. <!--小米厂商配置——开始-->
  2. <meta-data
  3. android:name="MIPUSH_APPID"
  4. android:value="XM_${XIAOMI_APP_ID}" />
  5. <meta-data
  6. android:name="MIPUSH_APPKEY"
  7. android:value="XM_${XIAOMI_APP_KEY}" />
  8. <!--小米厂商配置——结束-->
  9. <!--魅族厂商配置——开始-->
  10. <meta-data
  11. android:name="MEIZUPUSH_APPID"
  12. android:value="MZ_${MEIZU_APP_ID}" />
  13. <meta-data
  14. android:name="MEIZUPUSH_APPKEY"
  15. android:value="MZ_${MEIZU_APP_KEY}" />
  16. <!--魅族厂商配置——结束-->
  17. <!--华为厂商配置——开始-->
  18. <meta-data
  19. android:name="com.huawei.hms.client.appid"
  20. android:value="${HUAWEI_APP_ID}" />
  21. <!--华为厂商配置——结束-->
  22. <!--OPPO厂商配置——开始-->
  23. <meta-data
  24. android:name="OPPOPUSH_APPKEY"
  25. android:value="OP_${OPPO_APP_KEY}" />
  26. <meta-data
  27. android:name="OPPOPUSH_APPSECRET"
  28. android:value="OP_${OPPO_APP_SECRET}" />
  29. <!--OPPO厂商配置——结束-->
  30. <!--VIVO厂商配置——开始-->
  31. <meta-data
  32. android:name="com.vivo.push.app_id"
  33. android:value="${VIVO_APP_ID}" />
  34. <meta-data
  35. android:name="com.vivo.push.api_key"
  36. android:value="${VIVO_APP_KEY}" />
  37. <!--VIVO厂商配置——结束-->

修改build.gradle,添加对应平台申请的appkey或appid(键名必须统一,如XIAOMI_APP_ID必须同时存在于build.gradle文件和Androidmanifest.xml文件中),如下所示:

  1. android {
  2. defaultConfig {
  3. manifestPlaceholders = [
  4. "XIAOMI_APP_ID":"ccccccccc",
  5. "XIAOMI_APP_KEY":"aaaaaaaaaaaaaa"
  6. ]
  7. }
  8. }

dcloud_properties.xml配置

在properties中添加如下配置,features节点与services节点必须同时配置!

  1. <properties>
  2. <features>
  3. <feature name="Push" value="io.dcloud.feature.aps.APSFeatureImpl">
  4. <module name="unipush" value="io.dcloud.feature.unipush.GTPushService"/>
  5. </feature>
  6. </features>
  7. <services>
  8. <service name="push" value="io.dcloud.feature.aps.APSFeatureImpl"/>
  9. </services>
  10. </properties>

其余配置

OPPO推送

oppo集成uniPush时需在Androidmanifest.xml的入口activity中添加如下配置:

  1. <activity
  2. android:name="io.dcloud.PandoraEntry">
  3. <intent-filter>
  4. <action android:name="android.intent.action.MAIN" />
  5. <category android:name="android.intent.category.LAUNCHER" />
  6. </intent-filter>
  7. /*oppo配置开始*/
  8. <intent-filter>
  9. <action android:name="android.intent.action.oppopush" />
  10. <category android:name="android.intent.category.DEFAULT" />
  11. </intent-filter>
  12. /*oppo配置结束*/
  13. </activity>

当添加了push-3.0.0.aar库时

在app目录下的build.gradle内添加

  1. dependencies {
  2. implementation 'com.google.code.gson:gson:2.6.2'
  3. implementation 'commons-codec:commons-codec:1.6'
  4. implementation 'androidx.annotation:annotation:1.1.0'
  5. }

华为推送

HBuilder X 3.0.7及以上版本uniPush更新了华为推送,新版本需要添加如下配置

  • 项目根目录下的build.gradle

    打开项目根目录下的build.gradle

    avatar

    需要在项目根目录下的build.gradle下添加华为推送的仓库地址,如下:

    1. buildscript {
    2. repositories {
    3. jcenter()
    4. google()
    5. // 配置HMS Core SDK的Maven仓地址。
    6. maven {url 'https://developer.huawei.com/repo/'}
    7. }
    8. dependencies {
    9. classpath 'com.android.tools.build:gradle:3.4.1'
    10. // 增加agcp配置。
    11. classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    12. }
    13. }
    14. allprojects {
    15. repositories {
    16. jcenter()
    17. google()
    18. // 配置HMS Core SDK的Maven仓地址。
    19. maven {url 'https://developer.huawei.com/repo/'}
    20. }
    21. }
  • 项目应用下的build.gradle

    打开需要集成华为推送的项目的build.gradle

    avatar

    在文件头apply plugin: ‘com.android.application’下一行添加如下配置。

    1. apply plugin: 'com.android.application'
    2. apply plugin: 'com.huawei.agconnect'

    “dependencies”中添加如下编译依赖

    注意:推送库版本号与uniPush对应,不能随便修改。

    1. dependencies {
    2. implementation 'com.huawei.hms:push:5.0.2.300'
    3. }
  • 添加添加华为推送的配置文件

    登录华为的AppGallery Connect网站,找到需要集成华为推送的应用,在“项目设置 > 常规”页面的“应用”区域,点击“agconnect-services.json”下载配置文件。

    avatar

    将“agconnect-services.json”文件拷贝到应用级根目录下。

    avatar

个推推送

需要拷贝的文件

需要引入工程的jar/aar文件

需要将以下jar/aar文件放到工程的libs目录下

路径 文件
SDK\libs aps-release.aar, aps-igexin-release.aar

Androidmainfest.xml文件需要修改的项

需要在application节点前添加权限

因Android L(android 5.0)系统自身限制,多个应用安装时,如果拥有同一个Service权限,会导致权限冲突,只能安装一个带有此权限的应用。对此,个推SDK在声明自定义权限时需要添加apk的包名以避免和其他使用个推的应用冲突。

  1. <uses-permission android:name="android.permission.INTERNET"/>
  2. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  3. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  4. <uses-permission android:name="android.permission.WAKE_LOCK"/>
  5. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  6. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  7. <uses-permission android:name="android.permission.VIBRATE"/>
  8. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  9. <uses-permission android:name="android.permission.CALL_PHONE"/>
  10. <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  11. <uses-permission android:name="getui.permission.GetuiService.$你的APK包名"/>
  12. <permission android:name="getui.permission.GetuiService.$你的APK包名" android:protectionLevel="normal"/>

<application>节点下配置如下代码

  1. <meta-data android:name="PUSH_APPID" android:value="$你自己的APPID"/>
  2. <meta-data android:name="PUSH_APPKEY" android:value="$你的appkey"/>
  3. <meta-data android:name="PUSH_APPSECRET" android:value="$你的appsecret"/>
  4. <service
  5. android:name="com.igexin.sdk.PushService"
  6. android:exported="true"
  7. android:label="NotificationCenter"
  8. android:process=":pushservice">
  9. <intent-filter>
  10. <action android:name="com.igexin.sdk.action.service.message"/>
  11. </intent-filter>
  12. </service>
  13. <receiver android:name="com.igexin.sdk.PushReceiver">
  14. <intent-filter>
  15. <action android:name="android.intent.action.BOOT_COMPLETED"/>
  16. <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
  17. <action android:name="android.intent.action.USER_PRESENT"/>
  18. <action android:name="com.igexin.sdk.action.refreshls"/>
  19. <action android:name="android.intent.action.MEDIA_MOUNTED"/>
  20. <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
  21. <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
  22. </intent-filter>
  23. </receiver>
  24. <activity
  25. android:name="com.igexin.sdk.PushActivity"
  26. android:excludeFromRecents="true"
  27. android:exported="false"
  28. android:process=":pushservice"
  29. android:taskAffinity="com.igexin.sdk.PushActivityTask"
  30. android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
  31. <activity
  32. android:name="com.igexin.sdk.GActivity"
  33. android:excludeFromRecents="true"
  34. android:exported="true"
  35. android:process=":pushservice"
  36. android:taskAffinity="com.igexin.sdk.PushActivityTask"
  37. android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
  38. <receiver android:name="io.dcloud.feature.apsGt.GTNotificationReceiver"
  39. android:exported="false">
  40. <intent-filter>
  41. <action android:name="android.intent.action.BOOT_COMPLETED"/>
  42. <action android:name="填写APK的包名.__CREATE_NOTIFICATION"/>
  43. <action android:name="填写APK的包名.__REMOVE_NOTIFICATION"/>
  44. <action android:name="填写APK的包名.__CLEAR_NOTIFICATION"/>
  45. <action android:name="填写APK的包名.__CLILK_NOTIFICATION"/>
  46. </intent-filter>
  47. </receiver>
  48. <service
  49. android:name="io.dcloud.feature.apsGt.GTNormalIntentService"/>

dcloud_properties.xml需要添加如下代码

dcloud_properties.xml文件在assets/data目录下

features节点下添加

  1. <feature name="Push" value="io.dcloud.feature.aps.APSFeatureImpl"><module name="igexin" value="io.dcloud.feature.apsGt.GTPushService"/></feature>

services节点下添加

  1. <service
  2. name="push"
  3. value="io.dcloud.feature.aps.APSFeatureImpl" />

谷歌推送

需要拷贝的文件

需要引入工程的jar/aar文件

需要将以下jar/aar文件放到工程的libs目录下

路径 文件
SDK\libs aps-release.aar, aps-unipush-gp-release.aar, aps-igexin-fcm-release.aar

注意:要想使用谷歌推送必须使用aps-unipush-gp-release.aar

配置指南

UniPush支持谷歌推送FCM配置指南

gradle配置

project级的build.gradle配置

在project级的build.gradle的buildscript->dependencies添加下面内容

  1. buildscript {
  2. dependencies {
  3. classpath 'com.google.gms:google-services:4.2.0'
  4. }
  5. }

如下图:

avatar

app级的build.gradle配置

  • 在build.gradle最前面添加下面内容
  1. apply plugin 'com.google.gms.google-services'
  • 在dependencies节点下添加下面内容
  1. implementation 'com.google.firebase:firebase-core:16.0.8'
  2. implementation 'com.google.firebase:firebase-messaging:17.6.0'

如下图

avatar

  • 添加google-services.json

在创建好Firebase应用时,会有自动弹框指引下载googie-services.json,请根据指引下载google-services.json文件,并根据官网指引将google-services.json文件放在对应的文件夹下, 然后点击continue.

uniPush配置

uniPush

GooglePlay渠道配置

aar 引用

SDK提供aps-igexin-gp-release.aar和aps-unipush-gp-release.aar,打包应用上传google play时,替换原aps-igexin-release.aar或aps-unipush-release.aar。注意,google play版SDK与原版SDK存在冲突,所以使用时只能保留其中一个。

AndroidManifest.xml配置

  • google play版uniPush配置

在AndroidManifest.xml中添加如下配置。

  1. <activity
  2. android:name="com.igexin.sdk.PrivacyActivity"
  3. android:exported="false"/>
  • google play版个推配置

在原个推离线配置基础上将如下配置添加到AndroidManifest.xml中。

  1. <service
  2. android:name="io.dcloud.feature.apsGt.GTPushDevService"
  3. android:exported="true"
  4. android:label="PushService"
  5. android:process=":pushservice" />
  6. <activity
  7. android:name="com.igexin.sdk.PrivacyActivity"
  8. android:exported="false"/>

其余配置

uniPush

个推

FCM

Gradle配置

需要在project级的build.gradle设置

  1. buildscript {
  2. repositories {
  3. google() // Google's Maven repository
  4. }
  5. dependencies {
  6. // ...
  7. classpath 'com.google.gms:google-services:4.2.0' // Google Services plugin
  8. }
  9. }
  10. allprojects {
  11. // ...
  12. repositories {
  13. google() // Google's Maven repository
  14. // ...
  15. }
  16. }

app级的build.gradle设置

  • 在build.gradle最前面添加下面内容

    1. apply plugin: 'com.google.gms.google-services' // Google Services plugin
  • 在dependencies下添加下面内容

    1. dependencies {
    2. implementation 'com.google.firebase:firebase-messaging:23.0.0'
    3. }

Androidmainfest.xml文件需要修改的项

application节点内配置如下代码

  1. <application>
  2. //...
  3. <service
  4. android:name="io.dcloud.feature.fcm.FCMVendorService"
  5. android:exported="false">
  6. <intent-filter>
  7. <action android:name="com.google.firebase.MESSAGING_EVENT" />
  8. </intent-filter>
  9. </service>
  10. <meta-data
  11. android:name="com.google.firebase.messaging.default_notification_channel_id"
  12. android:value="%YOUR-CHANNEL-ID%" />
  13. <meta-data
  14. android:name="com.google.firebase.messaging.default_notification_icon"
  15. android:resource="%NOTIFICATION_ICON%" />
  16. //...
  17. </application>
  • YOUR-CHANNEL-ID设置为您自定义的通知的channelId ,
  • NOTIFICATION_ICON设置为推送消息的图片

需要拷贝的文件

添加google-services.json

在创建好Firebase应用时,会有自动弹框指引下载googie-services.json,请根据指引下载google-services.json文件,并根据官网指引将google-services.json文件放在对应的文件夹下, 然后点击continue.

需要引入工程的aar文件

需要将以下aar文件放到工程的libs目录下

路径 文件
SDK\libs aps-release.aar,aps-fcm-release.aar

dcloud_properties.xml需要添加如下代码

dcloud_properties.xml文件在assets/data目录下

  1. <feature name="Push" value="io.dcloud.feature.aps.APSFeatureImpl">
  2. <module name="fcm" value="io.dcloud.feature.fcm.FCMPushService" />
  3. </feature>