Dropbox.CoreAPIを使用したアプリ開発でファイルリスト取得、表示ができません。ご教授お願いします

44 views
Skip to first unread message

Rika Black

unread,
Dec 26, 2013, 2:48:27 AM12/26/13
to android-deve...@googlegroups.com
Androidアプリを作成しています。その際にDropboxとやりとりできるようにしたいと思っています。
Dropboxの認証には成功しますが。Dropboxのファイルリストを取得、表示することができません。
ファイルリストの表示の際はlayoutを用意しなければいけないのでしょうか?

アプリの機能として認証成功するとファイルリストが表示するようにしたいと思っています。
どのように表示させたら良いのでしょうかご教授お願いします。

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        AndroidAuthSession session = buildDropboxSession(); 
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);//認証開始
        
        mDBApi.getSession().startAuthentication(this);
    }
    @Override
    protected void onResume() {
        super.onResume();
        AndroidAuthSession session = mDBApi.getSession();
        
        if (session.authenticationSuccessful()) {//認証成功しているか確認
            try {
             Toast toast=Toast.makeText(this,R.string.drop_linked,1000);
toast.show();
                mDBApi.getSession().finishAuthentication();//認証終了
                AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
                storeDropboxKeys(tokens.key, tokens.secret);
                startActivity(new Intent(this, MainActivity.class));//元の画面に戻る(仮)実際には、ファイルリストを呼び出したい。
                finish();
            } catch (IllegalStateException e) {
              Log.i("DbAuthLog", "Error authenticating", e);
            }
        }
    } 


private void storeDropboxKeys(String key, String secret) {//アクセスキーの保存
SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS, 0);
        Editor edit = prefs.edit();
        edit.putString(APP_KEY, key);
        edit.putString(APP_SECRET, secret);
        edit.commit();
    }

//SharedPreferences から アクセスキーを取得する
    private String[] getKeys() {
        SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS, 0);
        String key = prefs.getString(APP_KEY, null);
        String secret = prefs.getString(APP_SECRET, null);
        if (key != null && secret != null) {
         String[] ret = new String[2];
         ret[0] = key;
         ret[1] = secret;
         return ret;
        } else {
         return null;
        }
    }     

private AndroidAuthSession buildDropboxSession() {//セッション作成
        AppKeyPair appKeyPair 
            = new AppKeyPair(DropBox.APP_KEY, DropBox.APP_SECRET);
        AndroidAuthSession session  = null;
        String[] keys = getKeys();
        if (keys == null) {
            session = new AndroidAuthSession(appKeyPair, DropBox.ACCESS_TYPE);
        } else {
            AccessTokenPair accessToken = new AccessTokenPair(keys[0], keys[1]);
            session = new AndroidAuthSession(appKeyPair, DropBox.ACCESS_TYPE, accessToken);
        }
        return session;
    }
}

上記のようにコードを書いています。
ディレクトリの情報をmetadataから取得しているようなのですが、取得方法は下記のコードで間違いないのでしょうか?
com.dropbox.client2.DropboxAPI.Entry entry;
try {
entry = mDBApi.metadata("path", 1000, null, true, null);
 if (!entry.isDir || entry.contents == null){
        //ファイルが見つからない。表示する
}
} catch (DropboxException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
Reply all
Reply to author
Forward
0 new messages