Android开发之极光推送基本步骤
2015-07-08 14:08
501 查看
【转】:http://wyong.blog.51cto.com/1115465/1402842
两天在研究推送的问题,后来确定了用极光推送,本人将整个过程整理一下:
1、到极光官网注册账号:https://www.jpush.cn/
2、创建应用,按照要求填写你的应用名称,包名提交
3、下载案例来玩玩,一般情况测试是能收到信息的
4、集成到自己的项目中,按照官网的集成http://docs.jpush.cn/pages/viewpage.action?pageId=557214
5、集成时将注意的要点,官网上也有说,但是我再强调一下,因为本人在集成的时候没注意导致推送失败:
(1)注意两个权限的包名填写,我们有可能直接用案例上的拷贝到自己的manifest中时没有替换掉包名,切记,要替换成自己的项目的包名(红色部分):
<permission android:name="com.xxx.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="com.xxx.permission.JPUSH_MESSAGE" />
(2)核心服务处的包名:
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true" >
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!--Required 显示通知栏 -->
<category android:name="com.xxx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
(3)按照官网的集成步骤去做就可以了。
6、要想自己打开信息查看,自己要写一个广播接收信息,判断这句,将bundle带到指定的Activity显示即可:
Bundle bundle = intent.getExtras();
if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
//打开自定义的Activity
Intent i = new Intent(context, JPushDetailActivity.class);
i.putExtras(bundle);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);}
经过以上的步骤,android客户端基本OK
两天在研究推送的问题,后来确定了用极光推送,本人将整个过程整理一下:
1、到极光官网注册账号:https://www.jpush.cn/
2、创建应用,按照要求填写你的应用名称,包名提交
3、下载案例来玩玩,一般情况测试是能收到信息的
4、集成到自己的项目中,按照官网的集成http://docs.jpush.cn/pages/viewpage.action?pageId=557214
5、集成时将注意的要点,官网上也有说,但是我再强调一下,因为本人在集成的时候没注意导致推送失败:
(1)注意两个权限的包名填写,我们有可能直接用案例上的拷贝到自己的manifest中时没有替换掉包名,切记,要替换成自己的项目的包名(红色部分):
<permission android:name="com.xxx.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="com.xxx.permission.JPUSH_MESSAGE" />
(2)核心服务处的包名:
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true" >
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!--Required 显示通知栏 -->
<category android:name="com.xxx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
(3)按照官网的集成步骤去做就可以了。
6、要想自己打开信息查看,自己要写一个广播接收信息,判断这句,将bundle带到指定的Activity显示即可:
Bundle bundle = intent.getExtras();
if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
//打开自定义的Activity
Intent i = new Intent(context, JPushDetailActivity.class);
i.putExtras(bundle);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);}
经过以上的步骤,android客户端基本OK
相关文章推荐
- Android高级用法之attrs使用
- Android的WebView通过JS调用java代码
- Android中字体设置Font
- Android禁止ViewPager的左右滑动
- AndroidAnnotations快速开发框架
- Android开发之实用小知识点汇总-2
- 优秀Android博客大全,整理了国内外大神博客/Github地址,是学习Android进阶的首选[转]
- Android 曾经的小Bug(常识)
- 关于Android studio创建时继承ActionBarActivity 如何修改的问题
- GitHub上史上最全的Android开源项目分类汇总
- 使用代码实现Android的清除数据的功能
- Android平台录音音量计的实现
- 【android】在Eclipse在联想引jar包源代码
- android 声明广播
- android sdk manager settings on os (mac)
- Android studio was unable to create a local connection in order...
- android实例 listview与sqlite数据绑定
- Android开发之实用小知识点汇总-1
- android 的四种枚举Context.MODE_PRIVATE ……
- Android 之一个简单计算器源代码