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);
}
}
}