其他分享
首页 > 其他分享> > Dropbox和Android – 通过API调用获取文件名

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.

标签:dropbox-api,android
来源: https://codeday.me/bug/20190902/1788337.html