List all the folder and files of Dropbox using Dropbox API

后端 未结 3 1026
梦谈多话
梦谈多话 2020-12-31 06:32

Am looking for the tutorial to display all the files and folder in a listview..but I didn\'t get anything..Does anyone here know that how can I show all the folder and files

相关标签:
3条回答
  • 2020-12-31 07:06

    please use this one , it is the latest 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;
            }
    
        }
    
    0 讨论(0)
  • 2020-12-31 07:14

    Try this code to list the files.....I don't know more about Dropbox, try it

     Entry contact = mDBApi.metadata("/", 0, null, true, null);
    
        List<Entry> CFolder = contact.contents;
        for (Entry entry : CFolder) {
        Log.i("DbExampleLog", "Filename: " + entry.fileName());}
    
    0 讨论(0)
  • 2020-12-31 07:15
                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;
    

    This is what i use. once you have stringarray fnames,you can display it in a listview.

    You can display it in a gridview like this

    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;
                        }
    
                        });
    
    0 讨论(0)
提交回复
热议问题