本文参考了华为推送平台官网及其Demo:http://developer.huawei.com/cn/consumer/wiki/index.php?title=接入说明

第一步

下载sdk,导入libs文件夹下,右键add as library。

第二步

将res目录中的values、layout、drawable等所有文件夹拷贝到自己的工程中。

第三步

将AndroidManifest.xml文件中的所有activity,receiver,service,meta-data拷 贝至自己的AndroidManifest.xml文件中。

第四步:

实现com. huawei.pushtest.receiver.MyReceiver,参看官方demo。



public class MyReceiver extends PushEventReceiver {

/*
* 显示Push消息
*/
public void showPushMessage(int type, String msg) {
HuaWeiTestActivity mPustTestActivity = AppApplication.instance().getMainActivity();
if (mPustTestActivity != null) {
Handler handler = mPustTestActivity.getHandler();
if (handler != null) {
Message message = handler.obtainMessage();
message.what = type;
message.obj = msg;
handler.sendMessageDelayed(message, 1L);
}
}
} @Override
public void onToken(Context context, String token, Bundle extras){
String belongId = extras.getString("belongId");
String content = "获取token和belongId成功,token = " + token + ",belongId = " + belongId;
Log.d(HuaWeiTestActivity.TAG, content);
showPushMessage(HuaWeiTestActivity.RECEIVE_TOKEN_MSG, content);
} @Override
public boolean onPushMsg(Context context, byte[] msg, Bundle bundle) {
try {
String content = "收到一条Push消息: " + new String(msg, "UTF-8");
Log.d(HuaWeiTestActivity.TAG, content);
showPushMessage(HuaWeiTestActivity.RECEIVE_PUSH_MSG, content);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} public void onEvent(Context context, Event event, Bundle extras) {
if (Event.NOTIFICATION_OPENED.equals(event) || Event.NOTIFICATION_CLICK_BTN.equals(event)) {
int notifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0);
if (0 != notifyId) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notifyId);
}
String content = "收到通知附加消息: " + extras.getString(BOUND_KEY.pushMsgKey);
Log.d(HuaWeiTestActivity.TAG, content);
showPushMessage(HuaWeiTestActivity.RECEIVE_NOTIFY_CLICK_MSG, content);
} else if (Event.PLUGINRSP.equals(event)) {
final int TYPE_LBS = 1;
final int TYPE_TAG = 2;
int reportType = extras.getInt(BOUND_KEY.PLUGINREPORTTYPE, -1);
boolean isSuccess = extras.getBoolean(BOUND_KEY.PLUGINREPORTRESULT, false);
String message = "";
if (TYPE_LBS == reportType) {
message = "LBS report result :";
} else if(TYPE_TAG == reportType) {
message = "TAG report result :";
}
Log.d(HuaWeiTestActivity.TAG, message + isSuccess);
showPushMessage(HuaWeiTestActivity.RECEIVE_TAG_LBS_MSG, message + isSuccess);
}
super.onEvent(context, event, extras);
}

}

第五步

在MyActivity的OnCreate()方法中添加 PushManager.requestToken(MyActivity.this);

第六步 测试

登录华为push后台,新建推送消息,如图。

最新文章

  1. FineReport根据点击次数奇偶性排序之字符型
  2. Spark的精简安装步骤---陈楠心血总结
  3. Eclipse 恢复删除的文件
  4. HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列
  5. VS2012编译可在WinXP兼容程序
  6. Android Animation初识
  7. 单/多行文本添加省略号 (o゚ω゚o)
  8. Android蓝牙A2dp profile的使用
  9. 正則表達式验证邮箱,qq,座机,手机,网址
  10. java编程规范之java命名规范
  11. 读书笔记--C陷阱与缺陷(二)
  12. EL&&JSTL
  13. 大白话Vue源码系列(01):万事开头难
  14. Unity 实现模拟按键
  15. SQL Server一致性错误修复案例总结
  16. Django 实现list页面检索
  17. Machine.config 文件中节点<machineKey>的强随机生成
  18. 2019.03.28 bzoj3325: [Scoi2013]密码(manacher+模拟)
  19. PubMed数据下载
  20. JavaScript从入门到精通(附光盘1张):作者:明日科技出版社:清华大学出版社出版时间:2012年09月

热门文章

  1. MySQL日志设置及查看方法
  2. [Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose
  3. iPad popView封装
  4. Delphi新语法 For ..In
  5. acme.sh建立SAN证书 和泛域名证书
  6. 如何下载最新版的 Adobe Flash Player
  7. js插件---图片懒加载echo.js结合 Amaze UI ScrollSpy 使用
  8. poj--1237--Drainage Ditches(最大流)
  9. spring security源码分析心得
  10. 线性同余同余方程组解法(excrt)