如何从一个驱动器(天空驱动器)中的文件夹ID读取文件?

时间:2014-12-30 10:52:45

标签: android onedrive

我已成功使用Live Sdk(One Drive)库登录Sky Drive帐户。并且还获取了My One Drive(Sky Drive)帐户的根目录的文件和文件夹。现在我想在我点击根目录中的文件夹时获取文件。

1 个答案:

答案 0 :(得分:1)

我得到了解决方案。它简单干净的代码我在这里粘贴从任何文件夹ID获取文件。 只需在文件夹ID 之后删除“文件”,例如Folder_id +“/ files” ,它就会检索所有文件 文件

 client.getAsync(Folder_id+"/files", new LiveOperationListener()
    {
        public void onComplete(LiveOperation operation) 
        {
              final JSONObject result = operation.getResult();
             final JSONArray data = result.optJSONArray("data");

             if (result.has("error")) 
                { 
                    final JSONObject error = result.optJSONObject("error"); 
                    final String message = error.optString("message"); 
                    final String code = error.optString("code"); 
                    ShowToast("mssg"+message); 
                    return; 
                } 

                for (int i = 0; i < data.length(); i++)
                { 
                    final JSONObject oneDriveItem = data.optJSONObject(i);
                    if (oneDriveItem != null) {
                        final String itemName = oneDriveItem.optString("name");
                        final String itemType = oneDriveItem.optString("type");
                        final String ids=oneDriveItem.optString("id");

                        ShowToast("Folder ID = " + ids + ", name = " + itemName);
                   //     ShowToast("Name: "+itemName+"\n"+"Type: "+itemType+"\n ID: "+ oneDriveItem.optString("id"));

                    } 
                } 
            //JSONObject result = operation.getResult();
            Log.e("realllt",result.toString() );

        }
        public void onError(LiveOperationException exception, LiveOperation operation) {
            resultTextView.setText("Error reading folder: " + exception.getMessage());
        }
    });