android上實現OMA下載

來源:互聯網
上載者:User

仔細研究了下OMA下載機制,把研究成果與大家分享。

 

網路處理層

package com.eshore.oma;<br />import java.util.HashMap;<br />import android.content.Context;<br />import com.eshore.ezone.net.BaseAccessor;<br />//網路層<br />public class OMAConnection {<br />public static OMADescription parseOMAUrl(Context context, String url) {<br />String[] arr = url.split("//?");<br />String urlString = arr[0];<br />HashMap<String, String> params = new HashMap<String, String>();<br />arr = arr[1].split("&");<br />for (int i = 0; i < arr.length; i++) {<br />String[] string = arr[i].split("=");<br />if (string.length == 2) {<br />params.put(string[0], string[1]);<br />} else {<br />params.put(string[0], "");<br />}<br />}<br />return BaseAccessor.omaRequest(context, urlString, params);<br />}</p><p>public static void installNotify(Context context,String url){<br />String[] arr = url.split("//?");<br />String urlString = arr[0];<br />HashMap<String, String> params = new HashMap<String, String>();<br />arr = arr[1].split("&");<br />for (int i = 0; i < arr.length; i++) {<br />String[] string = arr[i].split("=");<br />if (string.length == 2) {<br />params.put(string[0], string[1]);<br />} else {<br />params.put(string[0], "");<br />}<br />}<br />String result=BaseAccessor.deRequest(context, urlString, params);<br />}<br />}<br /> 

parserOMAUrl方法獲得OMA下載描述檔案

installNofiy方法在安裝完成時將最終狀態返回

 

 

 

模型層

package com.eshore.oma;<br />public class OMADescription {<br />public String objectURI;<br />public String installNotifyURI;<br />}<br /> 

objectURI是要下載對象的URI

installNotifyURI是安裝完成時需要通知伺服器的地址

 

 

將返回XML轉化成OMA下載描述對象

package com.eshore.oma;<br />import java.io.StringReader;<br />import javax.xml.parsers.DocumentBuilder;<br />import javax.xml.parsers.DocumentBuilderFactory;<br />import org.w3c.dom.Document;<br />import org.w3c.dom.Element;<br />import org.w3c.dom.NodeList;<br />import org.xml.sax.InputSource;<br />import com.eshore.ezone.util.Constants;<br />import android.content.SharedPreferences;<br />import android.util.Log;<br />public class OMAParser {<br />public static OMADescription parserString(String xml) {<br />Log.d("dddd", xml);<br />OMADescription omad = new OMADescription();<br />DocumentBuilderFactory docBuilderFactory = null;<br />DocumentBuilder docBuilder = null;<br />Document doc = null;<br />try {<br />docBuilderFactory = DocumentBuilderFactory.newInstance();<br />docBuilder = docBuilderFactory.newDocumentBuilder();<br />StringReader read = new StringReader(xml.replace('&', '*'));<br />InputSource source = new InputSource(read);<br />doc = docBuilder.parse(source);<br />Element root = doc.getDocumentElement();<br />NodeList nodeList = root.getElementsByTagName("objectURI");<br />omad.objectURI = nodeList.item(0).getFirstChild().getNodeValue()<br />.replace('*', '&');<br />NodeList nodeList2 = root.getElementsByTagName("installNotifyURI");<br />omad.installNotifyURI = nodeList2.item(0).getFirstChild().getNodeValue()<br />.replace('*', '&');<br />} catch (Exception e) {<br />e.printStackTrace();<br />}<br />return omad;<br />}<br />} 

 

描述符的格式如下

<media xmlns="http://www.openmobilealliance.org/xmlns/dd"><br /><objectURI></p><p>http://xxx.xxxx.xxx/cot/20100409095238.apkID=035000000000000008320000000000000000001858</p><p></objectURI><br /><size>123000</size><br /><type>application/x-cab-compressed</type><br /><name>dsds</name><br /><description>sss</description><br /><installNotifyURI></p><p>http://xxx.xxxx.xxx/report?ID=035000000000000008320000000000000000001858</p><p></installNotifyURI><br /><nextURL>http://xxx.xxxx.xxx/portalapp</nextURL><br /></media>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.