问题
I'm working on android app and I use Cordova and AngularJS
...
I want to open external link with InAppBrowser
and allow the user to download file from a link inside this site...
When I click the button that should open the InAppBrowser
it's opens the website but when I click on download link inside this site, nothing really happens...
The app have
"android.permission.WRITE_EXTERNAL_STORAGE"
permission
Thanks :)
回答1:
InAppBrowser doesn't allow download. You will need to modify plugin to allow it for downloading.
For android, inside platforms\android\src\org\apache\cordova\inappbrowser
method name private void navigate(String url) {
include
this.inAppWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
cordova.getActivity().startActivity(i);
}
});
before this line this.inAppWebView.requestFocus();
again same code in the method public void run() {
after this segment
if (clearAllCache) {
CookieManager.getInstance().removeAllCookie();
} else if (clearSessionCache) {
CookieManager.getInstance().removeSessionCookie();
}
inAppWebView.loadUrl(url);
in your .java file inside onCreate
appView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
add this two import import android.net.Uri; import android.webkit.DownloadListener;
Don't know about iOS
来源:https://stackoverflow.com/questions/30390826/download-file-from-external-website-with-inappbrowser-cordova