zoukankan      html  css  js  c++  java
  • 智游推送试用

    最近要做推送的功能,于是去了解了下社区推荐的智游推送zypush
    开发指南非常详细,按照这个配置,就可以出来了。

    1.申请appkey

    到www.zypush.com申请appkey

    2.导入文件

    将zhiyou_push.**.jar,liblptcpjin.so库以及push_notification.xml,push_download.xml文件导入到工程内部

    3.配置AndroidManifest.xml文件

    <注意:在配置过程中有些地方需要用到包名以及appkey>

    <!-- push service(必要) -->
    <service 
       android:name=”com.joboevan.push.service.PushService”>
    </service>
    
    <!--应用包名.PushReceiver 定义推送消息接收器,PushReceiver在SDK中有这个类-->
        <!-- <receiver android:name="YOUR_PACKAGENAME.PushReceiver" > -->
    <!--com.zypush.activity 这是我自己的包名-->
        <receiver android:name=”com.zypush.activity.PushRecevier”>
          <intent-filter>
           <!-- <action android:name=”com.zypush.android.intent.message.申请的appkey”/> -->
           <!--用户接收消息的action-->
           <action android:name=”com.zypush.android.intent.message.f262516bedf4c0f567b5659840920f94”/>
           <!--用户打开通知栏的action-->
           <action android:name=”com.zypush.android.intent.NOTIFICATION_OPENED.f262516bedf4c0f567b5659840920f94”/>
           <!-- 需要上传经纬度的action -->
           <action android:name=”com.zypush.android.intent.LBS_PUSH.f262516bedf4c0f567b5659840920f94”/>
          </intent-filter>
    </receiver>
    
    <!--- 心跳广播接收器注册(必要) -->
    <receiver
          android:name="com.joboevan.push.receiver.CheckConnectRecevier"
          android:enabled="true" />
    
    <!-- 网络改变广播监听 (必要)-->
            <receiver android:name="com.joboevan.push.receiver.NetworkReceiver" >
                <intent-filter >
                    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                </intent-filter>
            </receiver>
    
    <!--  android:authorities="packagename"此处填写包名 (必要)-->
            <provider
                android:authorities="com.zypush.activity"
                android:name="com.joboevan.push.providers.downloads.DownloadProvider" />
    
    <!-- 富媒体下载服务 (必要)-->
            <service android:name="com.joboevan.push.providers.downloads.DownloadService" />
    
    <!-- 富媒体下载接收器 (必要)-->
            <receiver
                android:exported="false"
                android:name="com.joboevan.push.providers.downloads.DownloadReceiver" >
                <intent-filter >
                    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                </intent-filter>
            </receiver>
    
    
    <!-- 配置的第三方参数属性   测试账号:zypush  密码:123456 -->
            <!-- http://www.zypush.com -->
            <meta-data
                android:name="ZYPUSH_APPKEY"
                android:value="f262516bedf4c0f567b5659840920f94" />

    推送服务运行所需要的权限

    代码块
    <!--自定义权限-->
         <permission android:name="com.zypush.permission.ACCESS_DOWNLOAD_MANAGER" />
    <!-- 网络权限 -->
        <uses-permission android:name="android.permission.INTERNET" />
        <!-- 网络状态权限 -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
         <!-- 往sdcard中写入数据的权限 -->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <!-- 获取手机设备号权限 -->
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <!-- 手机震动权限 -->
        <uses-permission android:name="android.permission.VIBRATE" />
        <!-- 引用富媒体自定义权限 -->
        <uses-permission android:name="com.zypush.permission.ACCESS_DOWNLOAD_MANAGER" />
        <!-- 唤醒权限 -->
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <!-- 获取当前任务权限 -->
        <uses-permission android:name="android.permission.GET_TASKS" />
        <!-- 悬浮窗体权限-->
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    
    
    <!-- 保留权限,后续添加功能需要用到 -->
        <!-- network网络开关权限(可选权限) -->
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
        <!-- 获取基站需要的权限 (可选权限)-->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    4.智游推送API接口说明

    4.1启动推送服务
    函数原型

    1
    2
    代码块
    PushManager.getInstance().connect(Context context,boolean isReconnect)
    

    参数
    context: Context对象
    isReconnect: 设置是否自动重连,true:表示断线以后自动重连,false标示断线以后不会自动重连

    返回值
    true:开启推送的条件都满足
    false:条件不满足开启推送

    示例

    1
    2
    代码块
    boolean result = PushManager.getInstance().connect(getApplicationContext(),true);
    

    4.2设置别名

    需要注意的是:这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。

    一个用户只可以设置一个别名,相当于一个人的名字,为了确保其唯一性,一般是用用户名设置别名,推送可以根据别名进行推送到个人客户端。设置别名超时时间为15秒,别名的最大长度不得超过40个字节,可以在PushReceiver中接收设置别名返回给客户端的返回值

    1
    2
    代码块
    PushManager.getInstance().bindAlias(Context context, String alias)
    

    参数
    context: Context对象

    alias:设置的别名

    返回值

    示例

    1
    2
    代码块
    PushManager.getInstance().bindAlias(this, “别名”);
    

    4.3设置标签

    需要注意的是:这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。

    标签的功能可以将一个整体划分成不同的群体,比如说将所有的用户划分成“男”用户和“女”用户,那么就可以给用户设置标签“男”或“女”。一个用户可以设置多个标签,多个标签的关系是或的关系。设置标签超时时间为15秒,单个标签的最大长度不得超过40个字节,并且不能为空,一个客户端最多可以设置100个标签。

    函数原型

    1
    2
    代码块
    PushManager.getInstance().setTags(Context context , List<String> tags)
    

    参数
    context: Context对象

    tags: 设置标签的List数组

    返回值

    示例

    1
    2
    代码块
    PushManager.getInstance().setTags(this,tags);
    

    4.4设置通知栏图标

    设置顶层通知栏图标

    函数原型

    1
    2
    代码块
    PushManager.getInstance().setNotificationIcon(Context context ,int value);
    

    参数

    context: Context对象

    value: 通知栏图标的资源id

    返回值

    示例

    1
    2
    代码块
    PushManager.getInstance().setNotificationIcon(this , R.drawable.icon);
    

    4.5设置是否开启智能提醒

    是否开启智能提醒。

    函数原型

    1
    2
    代码块
    PushManager.getInstance(). isOpenRemind(Context context , boolean state , String content , int days , int startTime , int endTime) ;
    

    参数
    context: Context对象

    state : 设置是否开启智能提醒,true:表示开启智能提醒,false表示暂停智能提醒

    content:设置提醒内容

    days:相隔几天之后没有打开应用,进行提醒

    startTime:在startTime之后进行提醒0-23

    endTime:在endTime之前进行提醒0-23

    返回值

    true:开启智能提醒成功
    false:开启智能提醒失败

    示例

    1
    2
    代码块
    boolean result = PushManager.getInstance().isOpenRemind(this, true, "这是一个智能提醒", 3, 0, 23) ;
    

    想要看更多的API说明,可以到www.zypush.com

    代码块
    package com.zypush.activity;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    
    import com.joboevan.push.bean.SendBroastBean;
    import com.joboevan.push.tool.Consts;
    import com.joboevan.push.tool.LBS;
    import com.joboevan.push.tool.Tool;
    
    /**
     * 推送消息接收器
     * 
     * **/
    public class PushReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            String action = intent.getAction();
            if (Consts.getACTION_RECEIVER_KEY(context).equals(action)) {
                Bundle bundle = intent.getExtras();
                String key = bundle.getString("key");
    
                if (Consts.MESSAGE_KEY_CONNECT.equals(key)) {
                    // 连接结果
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "连接成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "连接失败");
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_LOGIN.equals(key)) {
                    // 登陆结果
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "登陆成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "登陆失败");
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_SETALIAS.equals(key)) {
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "别名设置成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "别名设置失败");
                        break;
                    case Consts.RESULT_I:
                        Log.d("Log", "正在设置别名");
                        break;
                    default:
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_CLEANALIAS.equals(key)) {
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "清除别名成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "清除别名失败");
                        break;
                    case Consts.RESULT_I:
                        Log.d("Log", "正在清除别名");
                        break;
                    default:
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_SETTAGS.equals(key)) {
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "标签设置成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "标签设置失败");
                        break;
                    case Consts.RESULT_I:
                        Log.d("Log", "正在设置标签");
                        break;
                    default:
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_CLEANTAGS.equals(key)) {
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.RESULT_Y:
                        Log.d("Log", "标签清除成功");
                        break;
                    case Consts.RESULT_N:
                        Log.d("Log", "标签清除失败");
                        break;
                    case Consts.RESULT_I:
                        Log.d("Log", "正在清除标签");
                        break;
                    default:
                        break;
                    }
                } else if (Consts.MESSAGE_KEY_CUSTOM.equals(key)) {
                    // 接收自定义推送信息
                    String value = bundle.getString("value");
                    String flag = bundle.getString(Consts.MESSAGE_BACK_FLAG);
                    Log.w("Log", "推送自定义消息: " + value);
                    Log.w("Log", "推送自定义消息id: " + flag);
    
                    //这个方法是推送内部封装生成通知的方法
                    CustomNotification notification = new CustomNotification();
                    notification.createNotification(context);
                } else if (Consts.MESSAGE_KEY_NOTIFICATION.equals(key)) { // 如需在工程中展示通知标题和内容,请设置是否展示通知内容
                    String title = bundle.getString(Consts.NOTIFICATION_TITLE);
                    String content = bundle.getString(Consts.NOTIFICATION_CONTENT);
                    String ext = bundle.getString(Consts.NOTIFICATION_EXT);
                    String flag = bundle.getString(Consts.MESSAGE_BACK_FLAG);
                    Log.d("Log", "通知标题:" + title);
                    Log.d("Log", "通知内容:" + content);
                    Log.d("Log", "通知附加字段:" + ext);
                    Log.d("Log", "通知消息id:" + flag);
                } else if (Consts.MESSAGE_KEY_PUSHSTATECHANGED.equals(key)) { // 客户端与服务端的状态
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.PUSH_CONNECTSTATE_CONNECTING: // 通道连接
                        Log.d("Log", "推送服务已经连接");
                        break;
    
                    case Consts.PUSH_CONNECTSTATE_DISCONNECT: // 通道断开
                        Log.e("Log", "推送服务已经断开");
                        break;
                    }
                } else if (Consts.ACTION_RECEIVER_VERSION.equals(key)) {
                    int value = bundle.getInt("value");
    
                    switch (value) {
                    case Consts.VERSION_LATEST:
                        Log.d("Log","推送版本是最新版本:可用");
                        break;
                    case Consts.VERSION_OLD_PERMIT:
                        Log.d("Log","推送版本是老版本:可用");
                        break;
                    case Consts.VERSION_OLD_REFUSE:
                        Log.e("Log","推送版本是老版本:不可用");
                        break;
                    default:
                        break;
                    }
                } else if (Consts.CLIENT_DEVICE_ID.equals(key)) {
                    String device_id = bundle.getString("value");
                    Log.d("Log", "设备唯一标识:" + device_id);
                }
            } else if (Consts.getActionNotificationOpened(context).equals(action)) {
                Log.d("Log", "用户点击了通知");
                Bundle bundle = intent.getExtras() ;
                //通知标题
                String title = bundle.getString(Consts.NOTIFICATION_TITLE);
                //通知内容
                String content = bundle.getString(Consts.NOTIFICATION_CONTENT);
                //通知附加字段
                String ext = bundle.getString(Consts.NOTIFICATION_EXT);
                //通知消息flag
                String flag = bundle.getString(Consts.MESSAGE_BACK_FLAG);
    
                Intent i = new Intent(context, TestActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            } else if (Consts.getActionLbsPush(context).equals(action)) { // 接收到广播,需要上传经纬度
                Log.d("Log", "需要上传经纬度信息");
                // 请调用上传经纬度的接口,此处是写的固定的百度经纬度
                // 参数分别为context对象,经度,纬度,类型(需要通过枚举类获取,分为GPS,百度,google三种经纬度类型)
                String method = LBS.BAIDU.method(); // 获取经纬度类型
                PushMethodImpl.getInstance().UploadGpsMessage(context,"0", "0", method);
            }
        }
    
    }
  • 相关阅读:
    幂次法则power law
    异常值探测的相关理论及方法
    Dynamics CRM2013 1:N关系 sub-grid中的“添加现有项”和“添加新建项”功能详解
    Microsoft Office Excel cannot access the file, There are several possible reasons
    matlab学习日志之并行运算
    Live555 直播源 以及MediaSubsession
    ajax跨域简单请求与复杂请求
    javaScript遍历对象、数组总结
    PHP正则表达式
    语法环境 变量 数据类型 转换 销毁和传值
  • 原文地址:https://www.cnblogs.com/nanhai/p/3556326.html
Copyright © 2011-2022 走看看