从google+/picasa android下载视频

从google+/picasa android下载视频,android,android-fragments,google-plus,picasa,Android,Android Fragments,Google Plus,Picasa,我们需要从google+/picasa下载视频并将其存储到SD卡中。 你能请任何人帮我解决这个问题吗? 谷歌+/picasa 将URI转换为字节[],然后将字节[]存储到文件: InputStream videoStream = getActivity().getContentResolver().openInputStream(videoUri); byte bytes[] = ByteStreams.toByteArray(videoStream ); videoFile = new Fil

我们需要从google+/picasa下载视频并将其存储到SD卡中。 你能请任何人帮我解决这个问题吗? 谷歌+/picasa

将URI转换为字节[],然后将字节[]存储到文件:

InputStream videoStream = getActivity().getContentResolver().openInputStream(videoUri);
byte bytes[] = ByteStreams.toByteArray(videoStream );
videoFile = new File("abcd.mp4");
FileOutputStream out = new FileOutputStream(videoFile);
out.write(bytes);
out.close();
你能试试那个吗:

public String DownloadFromUrl(String DownloadUrl, String fileName) {

File SDCardRoot = null;
try {
    SDCardRoot = Environment.getExternalStorageDirectory();
    File files = new File(SDCardRoot+fileName);
    int sizeoffile;
    if(!files.exists()) 
    {
        File root = android.os.Environment.getExternalStorageDirectory();               

        File dir = new File (root.getAbsolutePath());
        if(dir.exists()==false) {
            dir.mkdirs();
        }

        URL url = new URL(DownloadUrl);
        File file = new File(dir, fileName);

        /* Open a connection to that URL. */
        URLConnection ucon = url.openConnection();
        sizeoffile = ucon.getContentLength();
        Log.d("SIZEOFFILE: ", sizeoffile+" BYTE");
        /*
         * Define InputStreams to read from the URLConnection.
         */
        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        /*
         * Read bytes to the Buffer until there is nothing more to read(-1).
         */
        ByteArrayBuffer baf = new ByteArrayBuffer(5000);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }
        /* Convert the Bytes read to a String. */
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
        fos.flush();
        fos.close();
    }
}
catch (IOException e) {
    e.getMessage();
}

return SDCardRoot+fileName; }

我最近遇到过这种情况

我第一次发现我收到的是一张图片而不是一段视频

但我不明白Facebook为什么能成功播放我通过Google+照片分享的在线视频

然后,我偶尔发现他们当前提供的文件是一个GIF文件,其原始扩展名位于contentUri的MediaStore.Images.Media.DISPLAY_NAME部分


哎呀

请向我们展示您迄今为止尝试的内容。请检查编辑的代码。现在视频存储在SD卡中,但不播放…:
Finally i found the solution.



 Uri videoUri = data.getData();
                    File videoFile = null;
                    final InputStream imageStream;
                    try {
                        imageStream = getActivity().getContentResolver().openInputStream(videoUri);
                        byte bytes[] = ByteStreams.toByteArray(imageStream);//IStoByteArray(imageStream);
                        videoFile = new File(Environment.getExternalStorageDirectory()+    "/"+System.currentTimeMillis()+".mp4");
                        videoFile.createNewFile();
                        FileOutputStream out = new FileOutputStream(videoFile);
                        out.write(bytes);
                        out.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }catch (Exception ee){
                        ee.printStackTrace();
                    }