Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have an app that displays a webview, and I wish to display the contents of a gdrive folder in this webview, and allow all users of the app to view files in that folder.
With the code that I currently have, I can't display the folder, and I copied the share link, with the permission that anyone with the link can view.

What I have tried:

import androidx.appcompat.widget.Toolbar;

import android.app.DownloadManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class info extends base {
private WebView web;
private Toolbar mtoolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);
        mtoolbar=(androidx.appcompat.widget.Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mtoolbar);
        web=findViewById(R.id.web);
        web.setWebViewClient(new client());
        WebSettings ws=web.getSettings();
        ws.setJavaScriptEnabled(true);
        web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        web.clearCache(true);
        web.clearHistory();
        web.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                DownloadManager.Request req=new DownloadManager.Request(Uri.parse(url));
                req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                DownloadManager dm=(DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(req);
                Toast.makeText(getApplicationContext(),"La descarga ha iniciado....",Toast.LENGTH_SHORT).show();
            }
        });
        web.loadUrl("url");
    }

    private class client extends WebViewClient {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    }
}
Posted
Updated 24-Nov-20 4:45am
v2
Comments
David Crow 1-Dec-20 22:27pm    
Since a WebView widget is just a scaled down browser, how would you go about displaying the contents of the folder in your browser? In other words, shouldn't you be calling loadUrl() with a valid URL?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900