【问题标题】:List all the folder and files of Dropbox using Dropbox API使用 Dropbox API 列出 Dropbox 的所有文件夹和文件
【发布时间】:2012-03-21 17:09:48
【问题描述】:

正在寻找在列表视图中显示所有文件和文件夹的教程..但我什么也没得到..这里有人知道如何将 Dropbox 的所有文件夹和文件显示到我的列表视图中..这样当我单击任何文件时..然后该文件开始下载..

我知道如何从 Dropbox 下载文件,但为此我需要以静态方式将该文件的名称放入我的代码中。

之后我还将对 .csv 文件使用过滤器...但我想在列表视图中显示所有文件。

谢谢..

【问题讨论】:

    标签: android dropbox


    【解决方案1】:
                String[] fnames = null;
                Entry dirent = mApi.metadata("/", 1000, null, true, null);
                ArrayList<Entry> files = new ArrayList<Entry>();
                ArrayList<String> dir=new ArrayList<String>();
                for (Entry ent: dirent.contents) 
                {
                    files.add(ent);// Add it to the list of thumbs we can choose from                       
                    //dir = new ArrayList<String>();
                    dir.add(new String(files.get(i++).path));
                }
                i=0;
                fnames=dir.toArray(new String[dir.size()]);
    
                return fnames;
    

    这就是我使用的。 一旦你有了 stringarray fnames,你就可以在列表视图中显示它。

    你可以像这样在gridview中显示它

    final GridView gv=(GridView)temp.findViewById(R.id.gridView1);
    ArrayAdapter<String> ad = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,fnames);
    gv.setBackgroundColor(Color.BLACK);
    gv.setNumColumns(3);
    gv.setGravity(Gravity.CENTER);
    gv.setAdapter(ad);
        gv.setBackgroundResource(R.drawable.black_cloud1);
    gv.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                int arg2, long arg3) {
                            // TODO Auto-generated method stub
                            Toast.makeText(mContext,gv.getItemAtPosition(arg2).toString(),Toast.LENGTH_SHORT).show();
    
                            temp.setData(fnames,gv.getItemAtPosition(arg2).toString());
    
                            return;
                        }
    
                        });
    

    【讨论】:

    • 这里的 mApi 是什么。能否提供示例演示。
    • @AmelJose 我在这里是什么?
    • @shailesh AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET); AndroidAuthSession session = new AndroidAuthSession(appKeys); DropboxAPI mApi = new DropboxAPI(session);
    【解决方案2】:

    试试这个代码来列出文件.....我对 Dropbox 不太了解,试试看

     Entry contact = mDBApi.metadata("/", 0, null, true, null);
    
        List<Entry> CFolder = contact.contents;
        for (Entry entry : CFolder) {
        Log.i("DbExampleLog", "Filename: " + entry.fileName());}
    

    【讨论】:

    • 什么是 mDBApi 请清除或给出演示项目的任何链接
    • @shailesh 我知道很晚了:DropboxAPI mDBApi
    【解决方案3】:

    请用这个,它是最新的api.....

     public void login(String accessToken) {
            DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("ManualApp")
                    .withHttpRequestor(OkHttp3Requestor.INSTANCE)
                    .build();
            mDbxClient = new DbxClientV2(requestConfig, accessToken);
        }
    
        public List<Metadata> getListFile(String path) {
    
            if (mDbxClient == null) {
                RkLogger.e("get files error", "must login first please");
                return null;
            }
    
            try {
                return mDbxClient.files().listFolder(path).getEntries();
            } catch (DbxException e) {
                RkLogger.e("DbxException ", e.toString());
                return null;
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多