http://www.push-notification.org/

APNS 是什么?

APNS (Android Push Notification Service) 是一种在 android 上轻松实现 push notification 的功能的解决方案. 只需申请一个 API Key, 经过简单的步骤即可实现 push notification 的功能.

特点:

  • 快速集成:提供一种比C2DM更加快捷的使用方式,避免各种限制.
  • 无需架设服务器:通过使用"云服务",减少额外服务器负担.
  • 通用性强:可以整合各种平台,适用性强,即将推出 html sdk, 使 web app 也可以集成此服务.
  • 耗电少,占用流量少.

  • 获取 API

    如何在 Android 应用中使用 Notification ?

    a) 在应用中添加 APNS 功能

    1. 下载 libaray: com_apns.jar
    2. 将com_apns.jar添加到工程

      在工程上右键打开“属性”,选择 “Java Build Path”, 在 Libraries 中选择 “Add External JARs”, 选择下载的 com_apns.jar.

    3. 接收 push notification
      使用BroadcastReceiver接收系统广播:public class MyBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {     if (intent.getAction().equals(APNService.ON_NOTIFICATION)) {String str = intent.getStringExtra("data");//todo, 处理收到的消息 } }}
    4. 启动 Push Notification Service
      发送Intent 启动服务,将 chanel Id 以及 此设备的标识 (chanel中唯一表示此设备的字符串) 传递过去:     Intent intent = new Intent(APNService.START);    intent.putExtra("ch", chanel);    intent.putExtra("devId", devId);    startService(intent);
      Notes Chanel Id 在申请 API 后,登录开发者页面会看到. devId: chanel 内设备标识,要在chanel内保持唯一.
    5. 配置 AndroidManifest.xml
      ...<application android:icon="@drawable/icon"    ...  <service android:name="com.apns.APNSService" android:label="APNS">         <intent-filter>             <action android:name="com.apns.APNService.START" />             <action android:name="com.apns.APNService.STOP" />             <category android:name="android.intent.category.DEFAULT"/>         </intent-filter> </service> <receiver android:name="MyBroadcastReceiver">      <intent-filter>          <action android:name="com.apnsd.APNService.NOTIFICATION" />      </intent-filter> </receiver></application><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />...


    b) 发送 Notification 到设备

    通过 rest 接口发送 Notification:
    http://www.push-notification.org/handlers/apns_v1.php?ch=YourChannelId&devId=xxxxx&msg =hello world&random=0123&hash=HashCode

    ch:Channel IddevId:接收设备 Idmsg:消息random:随机数hash:md5(ch + devId + msg + random + apiKey)
    Notes 申请API后,可登录开发者页面使用测试控制台进行API测试.

    更多相关文章

    1. android模拟器无法启动 找不到设备
    2. android中自动提示、补全、连接的功能实现
    3. 再谈 android 设备SN的获取 续 android 设备唯一码的获取,Cpu号,Ma
    4. Android 集成百度地图实现设备定位
    5. 【Android-View】基于原生View的简单功能定制
    6. android 学习笔记3--静默安装功能的实现
    7. 读取 android 设备的电池信息
    8. Ubuntu识别不到Android设备
    9. Android 拨打电话功能

    随机推荐

    1. Android之十一实现登陆页面分析
    2. android编码问题
    3. Ubuntu 配置 Android 开发 环境
    4. Android加载/处理超大图片神器!
    5. Android XML文件 Error parsing XML: unb
    6. ReactNative 调用Android 原生(二)——原生
    7. android相机预览
    8. Android学习_android镜像
    9. android之修改系统自带ProgressDialog样
    10. 使用android studio中遇到的常见问题及解