mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Merge pull request #5209 from nextcloud/ooDownloadFile
OnlyOffice: make download possible
This commit is contained in:
commit
8dc162960b
3 changed files with 23 additions and 17 deletions
|
@ -23,8 +23,11 @@
|
|||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
|
@ -192,6 +195,21 @@ public abstract class EditorWebView extends ExternalSiteWebView {
|
|||
}
|
||||
}
|
||||
|
||||
protected void downloadFile(Uri url) {
|
||||
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(url);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
|
||||
downloadmanager.enqueue(request);
|
||||
}
|
||||
|
||||
public class MobileInterface {
|
||||
@JavascriptInterface
|
||||
public void close() {
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -235,21 +233,6 @@ public class RichDocumentsEditorWebView extends EditorWebView {
|
|||
new PrintAsyncTask(targetFile, url.toString(), new WeakReference<>(this)).execute();
|
||||
}
|
||||
|
||||
private void downloadFile(Uri url) {
|
||||
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(url);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
|
||||
downloadmanager.enqueue(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUrl(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
|
@ -57,6 +58,10 @@ class TextEditorWebView : EditorWebView() {
|
|||
|
||||
webview.addJavascriptInterface(MobileInterface(), "DirectEditingMobileInterface")
|
||||
|
||||
webview.setDownloadListener({ url, userAgent, contentDisposition, mimetype, contentLength ->
|
||||
downloadFile(Uri.parse(url))
|
||||
})
|
||||
|
||||
loadUrl(intent.getStringExtra(ExternalSiteWebView.EXTRA_URL))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue