add untested download code

pull/653/merge
Varun Patil 2023-05-08 20:02:33 -07:00
parent a6cf5ad190
commit 6f11b5eeba
2 changed files with 21 additions and 0 deletions

View File

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<application
android:allowBackup="true"

View File

@ -3,7 +3,10 @@ package gallery.memories;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.View;
@ -24,12 +27,14 @@ import gallery.memories.service.TimelineQuery;
public class NativeX {
public static final String TAG = "NativeX";
Activity mActivity;
WebView mWebView;
protected ImageService mImageService;
protected TimelineQuery mQuery;
public NativeX(Activity activity, WebView webView) {
mActivity = activity;
mWebView = webView;
mImageService = new ImageService(activity);
mQuery = new TimelineQuery(activity);
}
@ -82,6 +87,21 @@ public class NativeX {
}
}
@JavascriptInterface
public void downloadFromUrl(final String url) {
Uri uri = Uri.parse(url);
DownloadManager manager = (DownloadManager) mActivity.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
// Copy all cookies from the webview to the download request
String cookies = android.webkit.CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
// Start the download
manager.enqueue(request);
}
protected WebResourceResponse routerGet(final String path) throws Exception {
String[] parts = path.split("/");