炒现饭之友盟推送的简单实现
来源:互联网 发布:ubuntu 系统剪贴板 编辑:程序博客网 时间:2024/06/16 13:55
万能的第三方第一步:注册账号并创建应用拿到app_key和app_secret
第二步:下载SDK
文档地址和sdk下载地址
第三步:将下载的文件解压,里面有一个PushSDK,将其作为module导入项目中
第四步:配置manifast
<meta-data android:name="UMENG_APPKEY" android:value="593e2fd6310c937413000f70" /> <meta-data android:name="UMENG_MESSAGE_SECRET" android:value="222b7fbb8e9d2cf3a07c4dabd3a76274" />
里面的APPKEY和UMENG_MESSAGE_SECRET都是前面创建应用时拿到的
第五步:配置app下的build.gradle
在Application Module的build.gradle文件的dependencies下添加compile project(‘:PushSDK’)。
第六步:配置自定义的Application
新建一个MyApplication继承自Application,在manifast里面配置上
然后在MyApplication的onCreate()里注册推送
PushAgent mPushAgent = PushAgent.getInstance(this); //注册推送服务,每次调用register方法都会回调该接口 mPushAgent.register(new IUmengRegisterCallback() { @Override public void onSuccess(String deviceToken) { //注册成功会返回device token } @Override public void onFailure(String s, String s1) { } });
第七步:在所有的Activity 的onCreate 方法或在应用的BaseActivity的onCreate方法中添加:
PushAgent.getInstance(this).onAppStart();
这样就可以推送简单的消息了,推送的步骤:
进入:http://push.umeng.com/选择自己的应用
点击自己的应用进入–>点击消息列表–>新建消息
然后就是自己写消息的相关内容
最后点击提交,手机上就能够收到消息了
以上是简单的集成,接下来说说自定义消息样式:
- 1 : 在MyAPPlication里面添加自定义的
UmengMessageHandler messageHandler = new UmengMessageHandler() { @Override public Notification getNotification(Context context, UMessage msg) { switch (msg.builder_id) { case 1: Notification.Builder builder = new Notification.Builder(context); RemoteViews myNotificationView = new RemoteViews(context.getPackageName(), R.layout.notification_view); myNotificationView.setTextViewText(R.id.notification_title, msg.title); myNotificationView.setTextViewText(R.id.notification_text, msg.text); myNotificationView.setImageViewBitmap(R.id.notification_large_icon, getLargeIcon(context, msg)); myNotificationView.setImageViewResource(R.id.notification_small_icon, getSmallIconId(context, msg)); builder.setContent(myNotificationView) .setSmallIcon(getSmallIconId(context, msg)) .setTicker(msg.ticker) .setAutoCancel(true); return builder.getNotification(); default: //默认为0,若填写的builder_id并不存在,也使用默认。 return super.getNotification(context, msg); } } }; mPushAgent.setMessageHandler(messageHandler);
注意:这里的case 1就是通知样式编号:
只有当你样式编号写1的时候才会显示你自定义的布局
还有一点要注意的是自定义的图标要配置,并且在你的drawable文件夹下的图片文件
自定义的xml 的notification_view.xml文件代码为:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="64dp" > <ImageView android:id="@+id/notification_large_icon" android:layout_width="64dp" android:layout_height="64dp" android:scaleType="fitXY" android:src="@drawable/umeng_addalias" /> <TextView android:id="@+id/notification_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:layout_toRightOf="@+id/notification_large_icon" android:text="Title" android:textColor="#000000"/> <TextView android:id="@+id/notification_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/notification_title" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/notification_large_icon" android:text="Message" android:textColor="#000000"/> <ImageView android:id="@+id/notification_small_icon" android:layout_width="24dp" android:layout_height="24dp" android:scaleType="fitXY" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginRight="5dp" android:layout_marginBottom="5dp" android:src="@drawable/umeng_addalias" /></RelativeLayout>
这样就可以发送自定义的样式通知消息了
阅读全文
0 0
- 炒现饭之友盟推送的简单实现
- Android开发之实现简单的极光推送
- 极光推送的简单实现
- 友盟推送获取简单的deviceToken
- 实现一个简单的服务端推送方案
- 极光推送的简单实现方法
- Notification推送的简单实现方式
- mqtt消息推送-推送服务简单实现
- 简单的极光推送
- iOS上简单推送通知(Push Notification)的实现
- 实现一个简单的服务端推送方案-实例篇Polling
- 实现一个简单的服务端推送方案-实例篇Push
- iOS上简单推送通知(Push Notification)的实现
- 如何实现一个简单的Android推送模块-Socket连接
- java websocket实现简单的即时通讯 消息推送
- 教你实现简单的极光推送-Eclipse
- 实现一个简单的服务端推送方案-实例篇Push
- serlvet实现简单的伪流传输推送视频网站
- eclipse 创建模拟器 出现 "No system images installed for this target" 问题
- 参数ENABLE_GOLDENGATE_REPLICATION
- gerrit集成gitweb
- elasticsearch基础知识
- 继承
- 炒现饭之友盟推送的简单实现
- Maven Tomcat7 插件部署Java Web应用
- CAD .NET v12发布,提高GDI+可视化速度并可导入AutoCAD®DWG 2018
- 进程通信之管道
- html5新增api(持续更新)
- T4系列文章之3:T4语法的介绍
- Hadoop--创建Hadoop集群
- SE01 Unit03 日期操作 、 集合框架
- nginx和Apache该怎么选