2

私はドロップボックスに取り組んでいます。ドキュメントを見ました。これはリストを表示する私のコードです:

Entry entryCheck = mApi.metadata("/", 100, null, true, null);
Log.i("Item Name", entryCheck.fileName());
Log.i("Is Folder", String.valueOf(entryCheck.isDir));

ドロップボックスからすべてのリストを取得しましたが、私の質問は

  1. ここで entryCheck.isDir は、ファイルまたはディレクトリの場合に常に真の値を提供するため、ファイルまたはディレクトリをどのように知ることができますか?
  2. そのファイルをダウンロードした方法。

私はこれを試しましたが、うまくいきません:

private boolean downloadDropboxFile(String dbPath, File localFile,
        DropboxAPI<?> api) throws IOException {
    BufferedInputStream br = null;
    BufferedOutputStream bw = null;
    try {
        if (!localFile.exists()) {
            localFile.createNewFile(); // otherwise dropbox client will fail
            // silently
        }                   

        DropboxInputStream fin = mApi.getFileStream("dropbox", dbPath);
        br = new BufferedInputStream(fin);
        bw = new BufferedOutputStream(new FileOutputStream(localFile));

        byte[] buffer = new byte[4096];
        int read;
        while (true) {
            read = br.read(buffer);
            if (read <= 0) {
                break;
            }
            bw.write(buffer, 0, read);
        }
    } catch (DropboxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        // in finally block:
        if (bw != null) {
            bw.close();
        }
        if (br != null) {
            br.close();
        }
    }

    return true;
}
4

1 に答える 1

1

これはうまくいきます

String inPath ="mnt/sdcard/"+filename;
File file=new File(inPath);           
try {

    mFos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
    mErrorMsg = "Couldn't create a local file to store the image";
    return false;
}

mApi.getFile("/"+filename, null, mFos, null);

これにより、ファイルがダウンロードされ、sdcard の場所に保存されますinPath。メインスレッドではなく、新しいスレッドで実行する必要があります。AsyncTask を使用してください。 http://www.androiddesignpatterns.com/2012/06/app-force-close-honeycomb-ics.html このリンクで理由が説明されています..

于 2012-06-27T15:23:44.747 に答える