百度推送(Push)简单集成
2016-06-24 10:04
330 查看
//百度推送初始化配置
private void initPush() {Utils.logStringCache = Utils.getLogText(getApplicationContext());Resources resource = this.getResources();String pkgName = this.getPackageName();PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY,Utils.getMetaValue(MainActivity.this, "api_key"));// Push: 如果想基于地理位置推送,可以打开支持地理位置的推送的开关// PushManager.enableLbs(getApplicationContext());// Push: 设置自定义的通知样式,具体API介绍见用户手册,如果想使用系统默认的可以不加这段代码// 请在通知推送界面中,高级设置->通知栏样式->自定义样式,选中并且填写值:1,// 与下方代码中 PushManager.setNotificationBuilder(this, 1, cBuilder)中的第二个参数对应CustomPushNotificationBuilder cBuilder = new CustomPushNotificationBuilder(resource.getIdentifier("notification_custom_builder", "layout", pkgName),resource.getIdentifier("notification_icon", "id", pkgName),resource.getIdentifier("notification_title", "id", pkgName),resource.getIdentifier("notification_text", "id", pkgName));cBuilder.setNotificationFlags(Notification.FLAG_AUTO_CANCEL);cBuilder.setNotificationDefaults(Notification.DEFAULT_VIBRATE);cBuilder.setStatusbarIcon(this.getApplicationInfo().icon);cBuilder.setLayoutDrawable(resource.getIdentifier("simple_notification_icon", "drawable", pkgName));cBuilder.setNotificationSound(Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6").toString());// 推送高级设置,通知栏样式设置为下面的IDPushManager.setNotificationBuilder(this, 1, cBuilder);}
<span style="background-color: rgb(255, 0, 0);"><strong><span style="font-size:18px;">//更改AndroidManifest.xml文件</span></strong></span>
<span style="background-color: rgb(255, 0, 0);"><strong><span style="font-size:18px;"> <!-- 在百度开发者中心查询应用的API Key --> <meta-data android:name="api_key" android:value="Ylg0X8oMflhuMuEWRAKeium8" /></span></strong></span>
相关文章推荐
- javaScript中push函数用法实例分析
- jquery中push()的用法(数组添加元素)
- perl push的用法及子程序返回值的反思
- JavaScript模拟push
- javascript使用数组的push方法完成快速排序
- JavaScript使用push方法添加一个元素到数组末尾用法实例
- JavaScript数组函数unshift、shift、pop、push使用实例
- Android 用adb pull或push 拷贝手机文件到到电脑上,拷贝手机数据库到电脑上,拷贝电脑数据库到手机上
- 简介JavaScript中的push()方法的使用
- 浅谈JavaScript的push(),pop(),concat()方法
- 通过 Push 来提高移动应用的活跃度 3ff0
- Eclipse中Pull参数问题
- Git使用入门 - 在Git上新建项目
- Docker 批量push脚本
- 基于dwr2.0的Push推送技术详细解析以及实例
- 浅谈JavaScript的push(),pop(),concat()方法
- 将在本地创建的Git仓库push到Git@OSC
- Fail to push agent from Primary site to client machine
- pycharm中github使用心得
- iOS远程推送