android项目集成极光推送

1、介绍

目前市场上的APP几乎都带推送功能,方便用户及时的获取后台的更新信息。下来我给大家介绍机关推送android端的集成方法。

2、首先去极光官网注册一个账号https://www.jiguang.cn/

3、登录进去在应用管理中添加自己的android项目,添加完成后会生成两个加密码masterSecret和appKey,这两个码很重要前后台都需要用到。

4、项目中使用

(1)在module的build.gradle中引入sdk

// 此处以JPush 3.1.6 版本为例。
implementation 'cn.jiguang.sdk:jcore:1.2.5'
// 此处以JCore 1.2.5 版本为例。
implementation files('libs/BaiduLBS_Android.jar')

(2)在manifest文件中添加如下配置,其中的PushSetActivity,SettingActivity,MyReceiver,MyJPushMessageReceiver文件在官网的example里复制到自己的项目里即可,MyReceiver作为消息接收,事件处理等

<!-- For test only 测试高级功能 -->
        <activity android:name=".PushSetActivity" android:label="@string/app_name"></activity>
        <!-- For test only 测试设置 -->
        <activity android:name=".SettingActivity" android:label="@string/app_name"></activity>
        <!-- For test only 测试状态通知栏,需要打开的Activity -->
        <activity android:name=".TestActivity" android:exported="false">
            <intent-filter>
                <action android:name="jpush.testAction" />
                <category android:name="jpush.testCategory" />
            </intent-filter>
        </activity>

        <!-- Rich push 核心功能 since 2.0.6-->
        <activity
            android:name="cn.jpush.android.ui.PopWinActivity"
            android:theme="@style/MyDialogStyle"
            android:exported="false">
        </activity>

        <!-- Required SDK核心功能-->
        <activity
            android:name="cn.jpush.android.ui.PushActivity"
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.ui.PushActivity" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="包名" />
            </intent-filter>
        </activity>

        <!-- Required SDK 核心功能-->
        <!-- 可配置android:process参数将PushService放在其他进程中 -->
        <service
            android:name="cn.jpush.android.service.PushService"
            android:process=":pushcore"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTER" />
                <action android:name="cn.jpush.android.intent.REPORT" />
                <action android:name="cn.jpush.android.intent.PushService" />
                <action android:name="cn.jpush.android.intent.PUSH_TIME" />
            </intent-filter>
        </service>
        <!-- since 3.0.9 Required SDK 核心功能-->
        <provider
            android:authorities="包名.DataProvider"
            android:name="cn.jpush.android.service.DataProvider"
            android:process=":pushcore"
            android:exported="false"
            />

        <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
        <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
        <service
            android:name="cn.jpush.android.service.DaemonService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.DaemonService" />
                <category android:name="包名" />
            </intent-filter>

        </service>
        <!-- since 3.1.0 Required SDK 核心功能-->
        <provider
            android:authorities="包名.DownloadProvider"
            android:name="cn.jpush.android.service.DownloadProvider"
            android:exported="true"
            />
        <!-- Required SDK核心功能-->
        <receiver
            android:name="cn.jpush.android.service.PushReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter android:priority="1000">
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />   <!--Required  显示通知栏 -->
                <category android:name="包名" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
            <!-- Optional -->
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <!-- Required SDK核心功能-->
        <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false"/>

        <!-- User defined.  For test only  用户自定义的广播接收器-->
        <receiver
            android:name=".MyReceiver"
            android:exported="false"
            android:enabled="true">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required  用户注册SDK的intent-->
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required  用户接收SDK消息的intent-->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required  用户接收SDK通知栏信息的intent-->
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required  用户打开自定义通知栏的intent-->
                <action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 -->
                <category android:name="包名" />
            </intent-filter>
        </receiver>

        <!-- User defined.  For test only  用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
        <receiver android:name=".MyJPushMessageReceiver">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
                <category android:name="包名"></category>
            </intent-filter>
        </receiver>
        <!-- Required  . Enable it you can get statistics data with channel -->
        <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
        <meta-data android:name="JPUSH_APPKEY" android:value="your appKey" /> <!--  </>值来自开发者平台取得的AppKey-->

(3)以上步骤完成后在官网上测试即可

猜你喜欢

转载自blog.csdn.net/dream2222222/article/details/86649715