有谁知道如何获取元数据列表...我的意思是在Android.i的dropbox中的app文件夹中存在的文件和文件夹需要获取文件和文件夹名称.. 现在再次我想在android.i中创建文件夹,从android.i中提到了dropbox docs.但是在那里找不到相同的.. 提前完成。
答案 0 :(得分:3)
在这里我做了什么,它对我来说很好。
SavedProperties.selectedAddress
是我的static
变量,其中包含要创建的文件夹的名称。
我在这里
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。
答案 1 :(得分:2)
我遇到了同样的问题,并找到了答案。访问完成后,如上所述创建一个新条目,但是 将参数“boolean list”设置为true。如果你这样做了,List就不会为null,你可以得到 使用for循环
所需的信息AccessTokenPair access = getStoredKeys();
mDBApi.getSession().setAccessTokenPair(access);
try {
// ----SET boolean list PARAMETER TO TRUE---------
Entry dropboxDir = mDBApi.metadata("/YOUR_FOLDER_NAME/", 0, null, true, null);
if (dropboxDir.isDir) {
List<Entry> contents = dropboxDir.contents;
if (contents != null) {
// ------CREATE NEW ENTRY AND THEN, GET THE FILENAME OF
// EVERY FILE
for (int i = 0; i < contents.size(); i++) {
Entry e = contents.get(i);
String a = e.fileName();
Log.d("dropbox", "FileName:" + a);
}
}
}
// ONLY A TEST CATCH, PLEASE DO WRIGHT EXCEPTION HANDLING HERE
} catch (Exception ex) {
Log.d("dropbox", "ERROR");
}
答案 2 :(得分:0)
Entry entries = mApi.metadata(Path, 100, null, true, null);
for (Entry e : entries.contents) {
if (!e.isDeleted) {
Log.i("Is Folder",String.valueOf(e.isDir));
Log.i("Item Name",e.fileName());
}
}
答案 3 :(得分:0)
如果您想从路径中检索所有FILES和FOLDER,请使用此代码,它会对您有所帮助。
我自己解决了。
String mPath="/"; //You can change the path here to specific FOLDER
Entry dirent = null;
try
{
dirent = mApi.metadata(mPath, 1000, null, true, null);
}
catch (DropboxException e)
{
System.out.println("Error Detail "+e.getMessage());
}
//执行循环并从PATH
中检索所有文件和文件夹
for (Entry ent: dirent.contents)
{
String name = ent.fileName();
System.out.println("My File in Folder "+name);
}