<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-31  評論-14  文章-0  trackbacks-0

    APNS 是什么?

    APNS (Android Push Notification Service) 是一種在 android 上輕松實現(xiàn) push notification 的功能的解決方案. 只需申請一個 API Key, 經(jīng)過簡單的步驟即可實現(xiàn) push notification 的功能.

    特點:

  • 快速集成:提供一種比C2DM更加快捷的使用方式,避免各種限制.
  • 無需架設(shè)服務(wù)器:通過使用"云服務(wù)",減少額外服務(wù)器負(fù)擔(dān).
  • 可以同時推送消息到網(wǎng)站頁面,android 手機(jī)
  • 耗電少,占用流量少.
  •  

    http://zen-mobi.com/get_api_key.php獲取apikey

    如何在 Android 應(yīng)用中使用 Notification ?

    a) 在應(yīng)用中添加 APNS 功能

    1. 下載 libaray: com_apns.jar
    2. 將com_apns.jar添加到工程
    3. 在工程上右鍵打開“屬性”,選擇 “Java Build Path”, 在 Libraries 中選擇 “Add External JARs”, 選擇下載的 com_apns.jar.

    4. 接收 push notification
    5. 使用BroadcastReceiver接收系統(tǒng)廣播:  public class MyBroadcastReceiver extends BroadcastReceiver { 	@Override 	public void onReceive(Context context, Intent intent) { 	     if (intent.getAction().equals(APNService.ON_NOTIFICATION)) { 			String str = intent.getStringExtra("data"); 			//todo, 處理收到的消息 		 }  	} } 
    6. 啟動 Push Notification Service
    7. 發(fā)送Intent 啟動服務(wù),將 chanel Id 以及 此設(shè)備的標(biāo)識 (chanel中唯一表示此設(shè)備的字符串) 傳遞過去:       Intent intent = new Intent(APNService.START);     intent.putExtra("ch", chanel);     intent.putExtra("devId", devId);     startService(intent); 
      Notes Chanel Id 在申請 API 后,登錄開發(fā)者頁面會看到. devId: chanel 內(nèi)設(shè)備標(biāo)識,要在chanel內(nèi)保持唯一.
    8. 配置 AndroidManifest.xml
    9. ... <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) 發(fā)送 Notification 到設(shè)備

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

    ch:Channel Id devId:接收設(shè)備 Id msg:消息 random:隨機(jī)數(shù) hash:md5(ch + devId + msg + random + apiKey)
    posted on 2012-07-21 22:15 zhanghu198901 閱讀(1745) 評論(1)  編輯  收藏

    評論:
    # re: android push notification serfice android中的push機(jī)制[未登錄] 2014-08-26 16:11 |
    啊啊   回復(fù)  更多評論
      

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 中文字幕一精品亚洲无线一区| 大地资源免费更新在线播放| 亚洲国产综合人成综合网站| 亚洲AV无码乱码在线观看代蜜桃| 18以下岁毛片在免费播放| 亚洲福利一区二区精品秒拍| 99re免费在线视频| 亚洲国产电影在线观看| 亚州免费一级毛片| 亚洲第一男人天堂| 国产成人精品男人免费| 亚洲一区二区三区免费| 亚洲国产一二三精品无码| 人人揉揉香蕉大免费不卡| 亚洲色图古典武侠| 成年在线网站免费观看无广告| 亚洲狠狠婷婷综合久久| 亚洲国产精品自在拍在线播放| 中文字幕视频在线免费观看| 91亚洲国产成人久久精品网站| 久久电影网午夜鲁丝片免费| 国产亚洲男人的天堂在线观看 | 无码人妻一区二区三区免费n鬼沢| 亚洲国产一区在线| 一区二区无码免费视频网站| 在线观看国产一区亚洲bd| 国产亚洲午夜高清国产拍精品 | www国产亚洲精品久久久日本| 国产精品视频全国免费观看| 亚洲天堂男人天堂| 免费高清av一区二区三区| 一区二区三区免费视频播放器| 亚洲精品成人图区| 免费在线观看你懂的| 99精品国产成人a∨免费看| 亚洲AV无码一区二区一二区| 亚洲伊人久久精品影院| 一二三四免费观看在线视频中文版| 国产成人亚洲毛片| 亚洲日本在线播放| 国产亚洲午夜高清国产拍精品|