1、创建一般处理程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;

 

namespace service
{
    ///


    /// $codebehindclassname$ 的摘要说明
    ///

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class MobileService : IHttpHandler
    {
       
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            XmlDocument doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.AppendChild(dec);
            //创建一个根节点(一级)
            XmlElement root = doc.CreateElement("First");
            doc.AppendChild(root);
            //创建节点(二级)
            XmlNode node = doc.CreateElement("Seconde");
            //创建节点(三级)
            XmlElement element1 = doc.CreateElement("Third1");
            element1.SetAttribute("Name", name);
            element1.SetAttribute("ID", "665");
            element1.InnerText = "Sam Comment";
            node.AppendChild(element1);

            XmlElement element2 = doc.CreateElement("Third2");
            element2.SetAttribute("Name", "Round");
            element2.SetAttribute("ID", "678");
            element2.InnerText = "Round Comment";
            node.AppendChild(element2);

            root.AppendChild(node);

            context.Response.Write(doc.InnerXml);
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    }
}

2、Java程序

package cn.itcast.service;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

import cn.itcast.domain.Video;
import cn.itcast.utils.StreamTool;

public class VideoService {
 /**
  * 从服务器获取最新的视频资讯
  * @return
  * @throws Throwable
  */
 public static List

 private static List

3、

package cn.itcast.domain;
/**
 * 视频资讯
 */
public class Video {
 private Integer id;
 private String title;
 private Integer timelength;
 
 public Video(){}
 
 public Video(Integer id, String title, Integer timelength) {
  this.id = id;
  this.title = title;
  this.timelength = timelength;
 }
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public Integer getTimelength() {
  return timelength;
 }
 public void setTimelength(Integer timelength) {
  this.timelength = timelength;
 }

 @Override
 public String toString() {
  return "Video [id=" + id + ", timelength=" + timelength + ", title="
    + title + "]";
 }
 
}

4、

package cn.itcast.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class StreamTool {
 /**
  * 从输入流中读取数据
  * @param inStream
  * @return
  * @throws Exception
  */
 public static byte[] readInputStream(InputStream inStream) throws Exception{
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  byte[] buffer = new byte[1024];
  int len = 0;
  while( (len = inStream.read(buffer)) !=-1 ){
   outStream.write(buffer, 0, len);
  }
  byte[] data = outStream.toByteArray();//网页的二进制数据
  outStream.close();
  inStream.close();
  return data;
 }
}

5、

package cn.itcast.videonews;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.itcast.domain.Video;
import cn.itcast.service.VideoService;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainActivity extends Activity {
    private static final String TAG = "MainActivity";
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        try {
   List

6、

package cn.itcast.videonews;

import java.util.List;

import cn.itcast.domain.Video;
import cn.itcast.service.VideoService;
import android.test.AndroidTestCase;
import android.util.Log;

public class VideoServiceTest extends AndroidTestCase {
 private static final String TAG = "VideoServiceTest";
 
 public void testGetLastVideos() throws Throwable{
  List

 

 

更多相关文章

  1. android 多媒体部分学习笔记十五-----视频录制
  2. 视频的播放
  3. android 学习视频汇总
  4. android 从Activity 获取 rootView 根节点
  5. Android SurfaceView 实现实时显示摄像头视频
  6. Android 使用MediaPlayer播放视频切换后台暂停再恢复互前台继续
  7. Android 音视频开发总结
  8. android 播放视频 Android 播放音频

随机推荐

  1. Android Looper中的MessageQueue消息处理
  2. interpolator
  3. View requires API level 14 (current mi
  4. WindowManagerService添加View流程
  5. Android控件开发之四----ListView(1)
  6. android学习笔记二
  7. android 布局随笔----用户登录界面
  8. android 扫描SD卡与系统文件
  9. (备忘)Android app中调用启动其他应用(系统
  10. Android帮助文档(第二部分)开发工具