Android - 解析uri时出错

时间:2013-05-25 03:23:13

标签: android parsing encoding uri

在我的应用中将网址解析为youtube视频时出现问题。

实际上我应该从服务器上读取视频ID,然后将它连接到像这样的youtube视频的普通链接

正确的网址是“https://www.youtube.com/watch?v=”+“Vuxmpogks64” 调用intent时解析后的url仅显示为http://www.youtube.com/watch?v=%EF%BB%BF Vuxmpogks64,并且找不到错误视频!

为什么这部分出现“%EF%BB%BF”?

代码如下

String myVideo = readAquaVideo();
        String[] ar = myVideo.split("[,]");
        video_id = ar[0];
        video_id = video_id.trim();


StringBuffer sb = new StringBuffer("");
        String url = "https://www.youtube.com/watch?v=";
        sb.append(url);
        sb.append(video_id);

        video_url = sb.toString().trim();



public static String readAquaVideo() {

        BufferedReader in = null;
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI("http://epic-demo.com/dunes/video.php"));

            HttpResponse response = client.execute(request);

            BufferedReader ien = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");

            while ((line = ien.readLine()) != null) {
                sb.append(line + NL);
            }
            ien.close();
            video_id = sb.toString();
            video_id = video_id.trim();

            Log.d("parsing video",video_id);

        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {

                    e.printStackTrace();
                }
            }
        }
        return video_id;
        }


Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(video_url));
startActivity(intent); 

0 个答案:

没有答案