Android端的极光配置

来源:互联网 发布:东方有线网络设置 编辑:程序博客网 时间:2024/06/05 15:34

Android端的极光配置

在build.gradle中

android括号里

  manifestPlaceholders = [   JPUSH_PKGNAME: applicationId,   JPUSH_APPKEY : "你的appkey", //JPush上注册的包名对应的appkey.   JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.

dependencies括号里

  compile 'cn.jiguang.sdk:jpush:3.0.9'  compile 'cn.jiguang.sdk:jcore:1.1.7'

在androidMainfest中

application里面

 <!-- Required SDK 核心功能 -->        <!-- 可配置android:process参数将PushService放在其他进程中 -->        <service            android:name="cn.jpush.android.service.PushService"            android:enabled="true"            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:name="cn.jpush.android.service.DataProvider"            android:authorities="你的包名.DataProvider"            android:exported="true"            tools:replace="android:authorities" />        <!-- 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>        <!-- Required SDK核心功能 -->        <receiver            android:name="cn.jpush.android.service.PushReceiver"            android:enabled="true">            <intent-filter android:priority="1000">                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />                <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核心功能 -->        <activity            android:name="cn.jpush.android.ui.PushActivity"            android:configChanges="orientation|keyboardHidden"            android:exported="false"            android:theme="@android:style/Theme.NoTitleBar">            <intent-filter>                <action android:name="cn.jpush.android.ui.PushActivity" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="你的包名" />            </intent-filter>        </activity>        <!-- SDK核心功能 -->        <activity            android:name="cn.jpush.android.ui.PopWinActivity"            android:configChanges="orientation|keyboardHidden"            android:exported="false"            android:theme="@style/MyDialogStyle">            <intent-filter>                <category android:name="android.intent.category.DEFAULT" />                <category android:name="你的包名" />            </intent-filter>        </activity>        <!-- Required SDK核心功能 -->        <service            android:name="cn.jpush.android.service.DownloadService"            android:enabled="true"            android:exported="false" />        <!-- Required SDK核心功能 -->        <receiver android:name="cn.jpush.android.service.AlarmReceiver" />        <!-- Required since 3.0.7 -->        <!-- 新的tag/alias接口结果返回需要开发者配置一个自定的广播 -->        <!-- 该广播需要继承JPush提供的JPushMessageReceiver类, 并如下新增一个 Intent-Filter -->        <receiver            android:name=".jpush.MyJPushMessageReceiver"            android:enabled="true">            <intent-filter>                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />                <category android:name="你的包名" />            </intent-filter>        </receiver>        <!-- User defined. 用户自定义的广播接收器 -->        <receiver            android:name=".jpush.MyReceiver"            android:enabled="true">            <intent-filter>                <!-- Required 用户注册SDK的intent -->                <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 用户打开自定义通知栏的intent -->                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />                <!-- 接收网络变化 连接/断开 since 1.6.3 -->                <action android:name="cn.jpush.android.intent.CONNECTION" />                <category android:name="你的包名" />            </intent-filter>        </receiver>        <!-- Required. For publish channel feature -->        <!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。 -->        <!-- 例如: -->        <!-- 发到 Google Play 的APK可以设置为 google-play; -->        <!-- 发到其他市场的 APK 可以设置为 xxx-market。 -->        <!-- 目前这个渠道统计功能的报表还未开放。 -->        <meta-data            android:name="JPUSH_CHANNEL"            android:value="developer-default"            tools:replace="android:value" />        <!-- Required. AppKey copied from Portal -->        <meta-data            android:name="JPUSH_APPKEY"            android:value="你的appkey"            tools:replace="android:value" />        <meta-data            android:name="JPUSH_PKGNAME"            android:value="你的包名"            tools:replace="android:value" />

application 外面

 <permission        android:name="你的包名.permission.JPUSH_MESSAGE"        android:protectionLevel="signature" />    <!-- Required -->    <uses-permission android:name="你的包名.permission.JPUSH_MESSAGE" />    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />    <uses-permission android:name="android.permission.WAKE_LOCK" />    <uses-permission android:name="android.permission.VIBRATE" />    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />    <uses-permission android:name="android.permission.WRITE_SETTINGS" />    <!-- Optional. Required for location feature -->    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />    <uses-permission android:name="android.permission.GET_TASKS" />

最后在项目的根目录下建立一个文件夹 jpush

里面存放两个的文件,看自己项目的情况而定,也可以值存放一个文件

  • MyReceiver
  • MyJPushMessageReceiver

这里两个文件的命名是根据前面androidMainfest中的配置命名的

<receiver            android:name=".jpush.MyJPushMessageReceiver"            android:enabled="true">            <intent-filter>                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />                <category android:name="你的包名" />            </intent-filter>        </receiver>        <!-- User defined. 用户自定义的广播接收器 -->        <receiver            android:name=".jpush.MyReceiver"            android:enabled="true">            <intent-filter>                <!-- Required 用户注册SDK的intent -->                <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 用户打开自定义通知栏的intent -->                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />                <!-- 接收网络变化 连接/断开 since 1.6.3 -->                <action android:name="cn.jpush.android.intent.CONNECTION" />                <category android:name="你的包名" />            </intent-filter>        </receiver>

MyReceiver的内容

public class MyReceiver extends BroadcastReceiver {    private static final String TAG = "JIGUANG-Example";    @Override    public void onReceive(Context context, Intent intent) {        try {            Bundle bundle = intent.getExtras();            Log.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));            if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {                String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);                Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);                //send the Registration Id to your server...            } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {                Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));                processCustomMessage(context, bundle);            } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {                Log.d(TAG, "[MyReceiver] 接收到推送下来的通知");                int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);                Log.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);            } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {                Log.d(TAG, "[MyReceiver] 用户点击打开了通知");            } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {                Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));                //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..            } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {                boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);                Log.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);            } else {                Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());            }        } catch (Exception e) {        }    }    // 打印所有的 intent extra 数据    private static String printBundle(Bundle bundle) {        StringBuilder sb = new StringBuilder();        for (String key : bundle.keySet()) {            if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {                sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));            } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {                sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));            } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {                if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {                    Log.i(TAG, "This message has no Extra data");                    continue;                }                try {                    JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));                    Iterator<String> it = json.keys();                    while (it.hasNext()) {                        String myKey = it.next();                        sb.append("\nkey:" + key + ", value: [" +                                myKey + " - " + json.optString(myKey) + "]");                    }                } catch (JSONException e) {                    Log.e(TAG, "Get message extra JSON error!");                }            } else {                sb.append("\nkey:" + key + ", value:" + bundle.getString(key));            }        }        return sb.toString();    }    //send msg to MainActivity    private void processCustomMessage(Context context, Bundle bundle) {    }}

MyJPushMessageReceiver中的内容

/** * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分) * */public class MyJPushMessageReceiver extends JPushMessageReceiver {    @Override    public void onTagOperatorResult(Context context,JPushMessage jPushMessage) {        super.onTagOperatorResult(context, jPushMessage);    }    @Override    public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){        super.onCheckTagOperatorResult(context, jPushMessage);    }    @Override    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {        super.onAliasOperatorResult(context, jPushMessage);    }}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苏宁电器发票丢了换电器怎么办 苹果5s访问限制密码忘了怎么办 京东买的暴风电视出现问题了怎么办 控水一个月的三角梅还没开花怎么办 帮别人办手机分期不还怎么办 国美在线没有信用卡分期不了怎么办 手机店办理分期被老板套现了怎么办 美的空调保修卡丢了怎么办 格力空调保修卡丢了怎么办 荣耀9i手机总是滑手怎么办? 春兰空调没发票不给修怎么办 洗衣机顶盖的安全开关坏了怎么办 苹果手机的开关健坏了怎么办 淘宝买的东西快递弄破损了怎么办 京东购买邮来手机里面没有怎么办 孕期建卡病历本丢了怎么办 四维检查胎儿心脏有缺陷怎么办 七个月的宝宝俩个蛋蛋都疝气怎么办 电脑有些网站看视频不能全屏怎么办 小米滑板车坏了售后不保修怎么办 红米4a电池不耐用怎么办 华为手机买个别人退货的怎么办 京东购物怎么查订单查询不到怎么办 退款了又收到货怎么办快递打电话 快递未收到货能退款商家拒绝怎么办 黑色牛仔裤有一块洗白了怎么办 黑色牛仔裤被洗衣液烧了怎么办 在蘑菇街退鞋子商家非说脏了怎么办 牛皮屑怎么办ke靠成都银康 微信订阅号取消关注之后还在怎么办 腾讯新闻红包领取说帐号异常怎么办 计算机职弥报名没选模块怎么办 有人用我手机注册有赞了怎么办 一件代发别人的货被投诉了怎么办 淘宝极速退款后商家拒收快递怎么办 运费险退到天猫垫付账户了怎么办 淘宝卖家食品有问题该怎么办 美团外卖不要辣椒给放了怎么办 旺旺卖家拒收我的消息怎么办 淘宝清空购物车大奖到上限了怎么办 游戏无响应除了退出还能怎么办