|
@@ -26,7 +26,9 @@ package com.owncloud.android.ui.activity;
|
|
|
|
|
|
import android.accounts.Account;
|
|
|
import android.annotation.SuppressLint;
|
|
|
+import android.app.DownloadManager;
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.net.Uri;
|
|
@@ -59,6 +61,8 @@ import com.owncloud.android.utils.DisplayUtils;
|
|
|
import com.owncloud.android.utils.MimeTypeUtil;
|
|
|
import com.owncloud.android.utils.glide.CustomGlideStreamLoader;
|
|
|
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
import org.parceler.Parcels;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
@@ -376,6 +380,31 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|
|
public void documentLoaded() {
|
|
|
runOnUiThread(RichDocumentsWebView.this::hideLoading);
|
|
|
}
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void downloadAs(String json) {
|
|
|
+ Uri downloadUrl;
|
|
|
+ try {
|
|
|
+ JSONObject downloadJson = new JSONObject(json);
|
|
|
+ downloadUrl = Uri.parse(downloadJson.getString("URL"));
|
|
|
+ } catch (JSONException e) {
|
|
|
+ Log_OC.e(this, "Failed to parse rename json message: " + e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
+
|
|
|
+ if (downloadmanager == null) {
|
|
|
+ DisplayUtils.showSnackMessage(webview, getString(R.string.failed_to_download));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DownloadManager.Request request = new DownloadManager.Request(downloadUrl);
|
|
|
+ request.allowScanningByMediaScanner();
|
|
|
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
+
|
|
|
+ downloadmanager.enqueue(request);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|