Iam working on webview for loading this Url, my code loads the url fine but whenever i clicked on a file in that url it does't downloading, i think the problem is with file extensions.
And i also need the files to be downloaded to a particular folder in sdcard.
at present iam using the bellow code i dont't understand what could be the wrong in my code
my Main Activity is
public class GosActs extends Activity{
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gos_acts);
web = (WebView)findViewById(R.id.wGAweb);
web.setWebViewClient(new WebViewClient(){
public void onLoadResource(WebView view, String url) {
//load.setVisibility(View.VISIBLE);
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.endsWith(".pdf")){
Uri source = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(source);
request.setDescription("requested GO downloading");
request.setTitle("go.pdf");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Go.pdf");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
} else if(url.endsWith(".docx")){
Uri source = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(source);
request.setDescription("requested GO downloading");
request.setTitle("go.pdf");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Go.pdf");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
else
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
//load.setVisibility(View.GONE);
}
});
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setDisplayZoomControls(false);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.loadUrl("http://goir.ap.gov.in");
}
my gos_acts.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#288A0E"
android:orientation="vertical" >
<WebView
android:id="@+id/wGAweb"
android:layout_margin="5dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_card" />
</LinearLayout>
and i also add required permissions in my minifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER"/>
<uses-permission android:name="android.permission.INTERNET"/>