安卓集成极光推送SDK
来源:互联网 发布:网络美女排行榜2016 编辑:程序博客网 时间:2024/05/17 02:38
在云计算飞速发展的今天,很多较复杂的功能已经不用开发者去摸索研究。直接在工程中集成别的公司开发的SDK。
集成极光推送SDK,完成安卓端手机推送
第一步,注册,添加应用,获得AppKey
第二步,新建项目
第三步,下载安卓端SDK,根据集成指南完成对SDK的集成
文档链接
第四步,测试
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); JPushInterface.setDebugMode(true); JPushInterface.init(this); }}控制台发送消息
第五步,自定义Receiver对推送进行处理
Manifest
<!-- User defined. For test only 用户自定义的广播接收器 --> <receiver android:name=".MyReceiver" android:enabled="true" android:exported="false"> <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="com.example.konghao.jpushtest1" /> </intent-filter> </receiver>MyReceiver
public class MyReceiver extends BroadcastReceiver { private static String TAG = "MyReceiver"; @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)); } 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] 用户点击打开了通知"); //打开自定义的Activity Intent i = new Intent(context, MessageActivity.class); i.putExtras(bundle); //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP ); context.startActivity(i); } 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(); }}第六步、分组发送推送,以别名为例
摘自文档:
Method - setAlias
调用此 API 来设置别名。
需要理解的是,这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。
支持的版本
开始支持的版本:3.0.7
接口定义
public static void setAlias(Context context, int sequence, String alias);
参数定义
sequence
- 用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。
alias
- 每次调用设置有效的别名,覆盖之前的设置。
- 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。
- 限制:alias 命名长度限制为 40 字节。(判断长度需采用UTF-8编码)
设置别名:
JPushInterface.setAlias(this, 1000, "test");
阅读全文
0 0
- 极光推送集成安卓sdk
- 安卓集成极光推送SDK
- 安卓集成极光推送SDK基础服务
- 安卓集成极光推送经验总结
- AndroidStudio集成极光推送SDK
- 极光推送SDK集成步骤
- 安卓集成 极光推送 自动集成 过程
- 极光推送,注册账户,集成SDK
- iOS 极光推送SDK的集成
- Swift项目集成极光推送SDK
- 极光推送 sdk 集成 全部推送 与别名标签推送
- 极光推送---安卓Demo
- 安卓 推送(极光)
- RN安卓极光推送
- C#推送安卓—极光推送
- 极光推送和友盟SDK的集成
- 远程推送,集成极光的SDK,证书制造
- 极光推送>>java SDK服务端集成后台项目
- jquery.Huploadify.免费的HTML5版uploadify无刷新上传插件
- c++ 模拟进程调度 (链表实现)
- 详解:面试题——谈谈你对多态的理解
- 初识VB.NET
- Spark SQL
- 安卓集成极光推送SDK
- 关于安卓环境配置中的Failed to load dx.jar
- hdu6006(状压dp)
- Linux下实现进度条程序的简单实现
- 图的遍历——DFS
- 【学习总结】git命令集笔记
- algo_Coordinate descent
- Ubuntu14.04安装LSD-SLAM
- 数据结构实验之图论三:判断可达性