WallyHale
WallyHale

Reputation: 408

Android - Unable to open a text file from SD Card in web view if path contains spaces?

I have a basic file browser which allows you to click and open various files, but I have found

a) If the directory contains a space, but the filename doesn't the web view app can't find the file eg. /mnt/sdcard/elocker/A Sub Folder/TextDocument.txt

b) If there are no spaces, everything is fine, the web view opens and displays the .txt file contents :) eg. /mnt/sdcard/elocker/ASubFolder/TextDocument.txt

To get the mime type and start an intent for a given files extension, I am using the following -

 Uri myFileUri = Uri.fromFile(aFile);

    try
    {
        Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
        String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(myFileUri.toString().toLowerCase());
        String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        myIntent.setDataAndType(myFileUri,mimetype);
        startActivityForResult(myIntent, 0);
    }

I'm sure people have come across this before, and it may just be a fundamental issue in that spaces cannot be used (in web view), but that seems a bit archaic and I would expect more from Android, so I'm guessing it's something I'm doing wrong ;)

=====

EDIT

The web view displays the following error, as you can see, the %20's are added by the system - "The webpage at content://com.android.htmlfileprovider/sdcard/elocker/A%20Sub%20Folder/TextDocument.txt?text/plain might be temporarily down or it may have moved permanently to a new web address."

Thanks in advance!

Upvotes: 0

Views: 3658

Answers (1)

WallyHale
WallyHale

Reputation: 408

This seemed to only happen on certain Android Virtual Devices, no such issues when testing on real devices (yet), and files all open as expected.

Upvotes: 1

Related Questions