android 杀不死的服务 ,主要是即时通讯,通知及时传送
2015-07-10 16:21
477 查看
原本我是不想写的,但是看到网上各种稀奇古怪的方法,对于那些我早都测试过, 测试结果,我早都忘记了,但是这样的demo(2014.7)做的这个demo.. 自己写的 ,还是别人给的建议我就忘记了,说重点,对于需要的权限manifest,这个 就不多扯,先看流程图的原理:
就是activity,和server2.加一个弱连接,加一个隐形的activity 显示逻辑,
就是直接开启activity,但是不显示页面,弱化页面,实际这个页面是开启的,
对于server杀不死,主要是干什么的。
的消息的。
但是对于IOS,苹果通过自己的后台苹果推送实现的,你死也没关系,
苹果的机制可以帮你实现,
对于代码,自己下吧,我就不贴代码了。
随便加一些,其他的方式:http://blog.sina.com.cn/s/blog_6271df6f0101a3ps.html
http://www.2cto.com/kf/201202/119069.html
这个写的比较全面,但是没有卵用:
/article/7659446.html
http://blog.sina.com.cn/s/blog_6271df6f0101a3pw.html
http://blog.sina.com.cn/s/blog_63edfc900100s2ga.html
demo
下载地址:http://download.csdn.net/detail/u012922981/8887831
最新理解 2015年7月15日10:16:38
因为用到jpush ,所以手机开启之后应用没有打开,
怎么让他及时的接到后台的推送呢,
很简单,你在manifest注册广播接收者,用广播接收者启动极光推送
的服务就好了
接收 开机广播android.intent.action.BOOT_COMPLETED
网络状态改变广播:android.net.conn.CONNECTIVITY_CHANGE
基本就能满足你的需求了
下面就是代码实现了:在manifest里面加
<receiver android:name="com.activity.taihulu.BootBroadcastReceiver"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </receiver>
添加个权限:高版本的用不到;
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
创建一个广播接收者:
package com.activity.taihulu; import com.push.taihulv.MyReceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { Intent serverIntent=new Intent(context,MyReceiver.class); context.startService(serverIntent); } }
这样你就可以及时的推送了,对于网络监听这是这样写的;
我就不再这里写了。具体地址:
http://www.open-open.com/lib/view/open1379302453943.html
相关文章推荐
- Android开发:带动画的分享效果
- android studio常用设置
- Android 双卡双待
- Android Wifi --自动连接指定SSID(各种加密方式均可)
- 关于android中PendingIntent.getBroadcase的注册广播
- Android实现圆角边框
- Android Selector 与 Shape 基本用法
- android的SQLite介绍
- android的parcelable接口
- android edittext只能输入字母和数字,默认弹出英文输入法
- Android_开源控件_DragSortListview
- android中定时任务的两种实现
- Android接口测试-JUnit入门
- 解决Android SDK Manager国内更新不了问题
- android 中解析json格式数据
- android指定DatePickerDialog样式并不显示年
- Android JNI知识
- Android SystemProperties设置/取得系统属性的用法总结
- 完美解决Android SDK Manager无法更新
- Android Please ensure that adb is correctly located at问题解决