Google Drive GET_CONTENT intent read file

后端 未结 2 2066
醉酒成梦
醉酒成梦 2021-02-05 10:16

I have an app on android that does some file sharing using cloud storages like dropbox. To start sharing I throw android.intent.action.SEND. On the list that is sh

2条回答
  •  渐次进展
    2021-02-05 10:30

    I was also facing the same problem. I used follow code to get file path from Google Drive file. It works for SkyDrive and also for DropBox.

    String filePath = null;
    Uri _uri = data.getData();
    Log.d("", "URI = " + _uri);                                       
    if(_uri != null && "content".equals(_uri.getScheme()))  {
        Cursor cursor = this.getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Files.FileColumns.DATA }, null, null, null);
        cursor.moveToFirst();   
        filePath = cursor.getString(0);
        cursor.close();
    } else {
         filePath = _uri.getPath();
    }
    Log.d("", "Chosen path = " + filePath);
    

    I'm using the intent to choose the file. Here is my code to choose the file.

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    String strType = "*/*";
    intent.setDataAndType(Uri.parse(dir.getAbsolutePath()), strType);
    startActivityForResult(intent, PICKFILE_RESULT_CODE);
    

    My code works fine and when I get file from internal or external memory. I want to get file from Google Drive with same code.

提交回复
热议问题