gfwilliams / Gadgetbridge

'Bangle.js Gadgetbridge' Android app development. Changed will eventually get pushed back to upstream Gadgetbridge
GNU Affero General Public License v3.0
5 stars 3 forks source link

App Loader can't show file upload/download dialogs #6

Closed gfwilliams closed 11 months ago

gfwilliams commented 2 years ago

First reported at https://github.com/espruino/BangleApps/issues/2073

Basically we can't upload or download files because the file chooser isn't shown. The standard code for doing this seems to be:

webView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype,
                                        long contentLength) {
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); //  fails with java.lang.IllegalArgumentException: Can not handle uri::
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);
            }
        });

But since we're now downloading a file but are instead downloading a blob - eg https://banglejs.com/614cd169-8d88-4b34-a57c-af34a162a03f - this fails with:

java.lang.IllegalArgumentException: Can not handle uri:: blob:https://banglejs.com/614cd169-8d88-4b34-a57c-af34a162a03f
        at android.app.DownloadManager$Request.checkUri(DownloadManager.java:779)
        at android.app.DownloadManager$Request.<init>(DownloadManager.java:762)
        at nodomain.freeyourgadget.gadgetbridge.devices.banglejs.AppsManagementActivity$3.onDownloadStart(AppsManagementActivity.java:185)
Moini commented 1 year ago

I ran into this issue, too, and didn't understand what was wrong. Thought it had to do with the specific file I was trying to download...

gfwilliams commented 11 months ago

I think this is actually fixed now anyway https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/c647c2647f1b14369edaf5d4597f14c369ec0510

Moini commented 11 months ago

Nice, thanks for the heads up, @gfwilliams !