package com.example.shery.youtubevideodownloader;
import android.Manifest;
import android.app.DownloadManager;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.content.pm.PackageManager.*;
public class MainActivity extends AppCompatActivity {
private WebView webView;
String url = "https://svidzdownloader.com/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String s, String s1, String s2, String s3, long l) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"Download");
DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
}
}
even i have added permission on manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I have a webview app and I want to download videos from it and I have added the download function on my code above so I added the permission on manifest but
when I pressed download button my app crashes
this is my logcat "No permission to write to /storage/emulated/0/Download/Download: Neither user 10143 nor current process has android.permission.WRITE_EXTERNAL_STORAGE"
so how to take runtime permission