android上实现OMA下载

仔细研究了下OMA下载机制,把研究成果与大家分享。

网络处理层

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

parserOMAUrl方法获得OMA下载描述文件

installNofiy方法在安装完成时将最终状态返回

模型层

package com.eshore.oma; public class OMADescription { public String objectURI; public String installNotifyURI; }

objectURI是要下载对象的URI

installNotifyURI是安装完成时需要通知服务器的地址

将返回XML转化成OMA下载描述对象

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

描述符的格式如下

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值