微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Dropbox和Android – 通过API调用获取文件名

有谁知道如何获取元数据列表…我的意思是在Android.i的dropBox中我们的app文件夹中存在的文件文件夹需要获取文件文件名称..
现在再次我想在android.i中创建文件夹从android.i reffered dropBox docs.but但是在那里找不到相同的..
Thanx提前.

解决方法:

在这里我做了什么,它对我来说很好.

SavedProperties.selectedAddress是我的静态变量,它包含要创建的文件夹的名称.

在这里

1)检查文件夹是否存在.

2)如果不存在则创建文件夹.

3)将文件上传到该文件夹​​.

    private void loadMetadata() 
    {


        // Metadata
        try 
        {
            Entry existingEntry = mApi.Metadata("/" + SavedProperties.selectedAddress , 1, null, false, null);
            if(existingEntry.isDir)
            {
                Log.d(TAG, "Folder exists : " + existingEntry.fileName());
                uploadPictures("/"+SavedProperties.selectedAddress + "/");
            }
        } 
        catch (DropBoxException  e) 
        {
            Log.d(TAG,"Folder does not exist..." + e.fillInStackTrace());
            try 
            {
                Entry createFolder = mApi.createFolder("/"+SavedProperties.selectedAddress);
                Log.d(TAG,"Folder created..." + createFolder.rev);
                uploadPictures("/"+SavedProperties.selectedAddress + "/");
            } 
            catch (DropBoxException e1)
            {
                 Log.d(TAG,"Create Folder DropBoxException : " + e1.fillInStackTrace() );
            }       
        }
    }

    private void uploadPictures(String uploadTo) 
    {
        // Uploading Pictures....
        FileInputStream inputStream = null;
        try 
        {
            for(int i =0 ; i < selectedImages.length; i++)
            {
                if(selectedImages[i]==0)
                {
                    String path = Picturegallery.images.get(i).toString().replace("file://", "");
                    String filename = Picturegallery.images.get(i).toString().split("/")[Picturegallery.images.get(i).toString().split("/").length-1];
                    File file = new File(path);
                    inputStream = new FileInputStream(file);
                    Entry newEntry = mApi.putFile(uploadTo + filename, inputStream, file.length(), null, null);
                    Log.i(TAG, "The uploaded file's rev is: " + newEntry.rev);
                    //Log.d(TAG,"Picturegallery " + Picturegallery.images.get(i).toString().split("/")[Picturegallery.images.get(i).toString().split("/").length-1]);
                }
            }
            progress.dismiss();
        } catch (DropBoxUnlinkedException e) {
            // User has unlinked, ask them to link again here.
            Log.e(TAG, "User has unlinked.");
        } catch (DropBoxException e) {
            Log.e(TAG, "Something went wrong while uploading.");
        } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found.");
        } 
        finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {}
            }
        }
    }

我在我的情况下使用了android sdk 1.3.1.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐