Android Webview Not Triggering A Href Download File
I have added the Download Manager , but it is not triggering the download event , can any body help . When user goes to webview download option and click a link to download a file
Solution 1:
Finally after searching lot and reading here about permission in Marshmallow API 23 >= , we need to give permission in run time . I solved my problem with this code ,
Oncreate method in MainActivity
int permissionCheck = ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
//requesting permission
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
} else {
Log.i(TAG , "Permission Granted");
}
and Overriding this Method
@OverridepublicvoidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
//you have the permission now.
Log.i(TAG , "Permission Already Granted");
}
}
Solution 2:
add these two lines in your mainfest file
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Solution 3:
Can you show the line in the html (the link from where you download) like:
<ahref='something'></a>
or do you use js to trigger it?
Because if you want you can use this:
Example
Download file when clicking on the link (instead of navigating to the file):
<a href="/images/myw3schoolsimage.jpg" download>
UPDATE
add this to your AndroidManifest.xml
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
EDIT
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="********"><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Post a Comment for "Android Webview Not Triggering A Href Download File"