android sdk差异,Android推送SDK集成对比

public class ExampleApplication extends Application {

@Override

public void onCreate() {

super.onCreate();

JPushInterface.setDebugMode(true);

JPushInterface.init(this);

}

}

//使用通知,请参考以下示例代码。

public class MyReceiver extends BroadcastReceiver {

private static final String TAG = "MyReceiver";

private NotificationManager nm;

@Override

public void onReceive(Context context, Intent intent) {

if (null == nm) {

nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

}

Bundle bundle = intent.getExtras();

Logger.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));

if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {

Logger.d(TAG, "JPush用户注册成功");

} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {

Logger.d(TAG, "接受到推送下来的自定义消息");

} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals   (intent.getAction())) {

Logger.d(TAG, "接受到推送下来的通知");

receivingNotification(context,bundle);

} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals (intent.getAction())) {

Logger.d(TAG, "用户点击打开了通知");

openNotification(context,bundle);

} else {

Logger.d(TAG, "Unhandled intent - " + intent.getAction());

}

}

private void receivingNotification(Context context, Bundle bundle){

String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);

Logger.d(TAG, " title : " + title);

String message = bundle.getString(JPushInterface.EXTRA_ALERT);

Logger.d(TAG, "message : " + message);

String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);

Logger.d(TAG, "extras : " + extras);

}

private void openNotification(Context context, Bundle bundle){

String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);

String myValue = "";

try {

JSONObject extrasJson = new JSONObject(extras);

myValue = extrasJson.optString("myKey");

} catch (Exception e) {

Logger.w(TAG, "Unexpected: extras is not a valid json", e);

return;

}

if (TYPE_THIS.equals(myValue)) {

Intent mIntent = new Intent(context, ThisActivity.class);

mIntent.putExtras(bundle);

mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(mIntent);

} else if (TYPE_ANOTHER.equals(myValue)){

Intent mIntent = new Intent(context, AnotherActivity.class);

mIntent.putExtras(bundle);

mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(mIntent);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安卓推送方案及比较 经常有朋友困扰于Android上面实现推送的技术,希望知道各种方案的优缺点、性能、开发难度等,于是特意写了这篇文章。 方案一: Google官方的服务: 但,通过对比研究发现C2DM机制存在以下缺点: 1)GCM要求Android系统必须是2.2以上的版本,所以对于不少2.2以前的系统没法推送 2)国内服务不稳定。而且不少国内的终端厂商纷纷把Google的服务去掉,替换上自己的。 3)需要用户绑定Google账号,但不少国内用户没有Google账号。 方案二: 利用MQTT协议,broker做代理服务器,但是随着用户的增多这个方案会有问题,因为broker的连接数有上限,到了一定程度后就无法连接了,这也就导致消息很难发送出去。 总之,连接数量有限制。 方案三: 基于XMPP协议,很多人都建议使用这个,谷歌官方的C2DM也是基于XMPP研发的,使用这个方案不会依赖android系统,也不依赖于谷歌服务器。 •XMPP协议比较费电费流量,对当前智能机的消耗太大 •在窄带网络和不稳定的(手机)网络都不是最优的选择。 方案四: 最近新出的一种是APNS,这个也不需要自己架设服务器(可以查看http://www.push-notification.mobi/),很简单,自己不用开发服务端。不过很少有人去用,不是很稳定 主要有以下特点: •快速集成:提供一种比C2DM更加快捷的使用方式,避免各种限制. •无需架设服务器:通过使用"云服务",减少额外服务器负担. •可以同时推送消息到网站页面,android 手机 •耗电少,占用流量少. 第三方服务: 目前也有不少第三方提供了推送服务,由于接入简单、服务比较专业可靠、还提供报表等,不少国内开发者和企业都采用这种方案。比如国外的parse、pubnub,国内的个推,都是这类。36kr前段时间有报道,新浪微博就是用的一家叫“个推”的第三方服务(有兴趣的朋友可以前往查看 http://www.igetuicom) 特点: •方便,易集成 •没有C2DM中的版本限制和必须用gmail绑定 •云服务,不用架设自己的服务器 •系统稳定、专业,能够承受高并发支持 •简单高效,并且省电
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值