0

My app needs to read a file selected by the user. I locate the file with the following:

       Intent getHandsIntent = new Intent(Intent.ACTION_GET_CONTENT);
       getHandsIntent.setType("file/*");
       startActivityForResult(getHandsIntent, GLOBALS.rqFindFile);

// then, in onActivityResult...
      if (RequestCode == GLOBALS.rqFindFile) {
            if (ResultCode == RESULT_OK) {
                String path = data.getData().getPath();
                readHandsFile(path);
            }

This works fine for local files. However, if the user chooses DropBox to locate the file, I get a message that the file is being downloaded before control returns to my onActivityResult code.

The path I get from the data is something of the form /filecache/635e8383-3a6e-424d-8437-d4d83421fcb8 but when I attempt to open this file for reading I am geting an Exception: /filecache/635e8383-3a6e-424d-8437-d4d83421fcb8: open failed: ENOENT (No such file or directory)

Any ideas?

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • "This works fine for local files" -- not really, since `file/` is not a valid MIME type prefix. You are just hoping that the user will have something that recognizes it or offers `*/*` support. Beyond that, a `Uri` is not a file, and `getPath()` is useless. – CommonsWare Mar 04 '20 at 12:34
  • Not sure that the file I'm looking for has a standard MIME type. The data source I wish to open can be one of a number of different standards for representing hands used in the card game, bridge. The two most important are .dlm, which is a text-based format and .dup, which is a binary format. I am therefore at a loss what parameter to pass to setType to allow the user to locate a file of either type.. – Keith Sheppard Mar 05 '20 at 14:51
  • Use `*/*`, the standard "I'll take anything" wildcard MIME type. – CommonsWare Mar 05 '20 at 14:59

0 Answers0