После трех дней поиска я понял, что андроид 6 или изменить разрешения. Но я не могу попросить oermisiunea сохранить файл. Я, наверное, примеры, но это не так, я сделал что-то не так. Пожалуйста, помогите.Android Marshmallow requestPermissions WRITE_EXTERNAL_STORAGE
String url = "http://grupovrt.ddns.net:81/v4.2.apk";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Virtual Romania Tv UPDATE");
request.setTitle("UPDATE Virtual Romania Tv");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
if (!checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
R.string.title_activity_categori))
{
Toast.makeText(getBaseContext(), "Not allowed to save files", Toast.LENGTH_SHORT).show();
} else {
// try to save the file
request.setDestinationInExternalPublicDir("/update", "v4.2.apk");
}
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Ошибка: Ошибка: (108, 49) Ошибка: не удается найти SYMBOL переменную WRITE_EXTERNAL_STORAGE
Edit.
Я искал, если дано разрешение на запись. , но я не знаю, как спросить разрешения, если это не так. Пожалуйста, помогите мне, я попробовал все, что нашел на google, но не смог. Я новичок.
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getBaseContext(), "Descarc noi actualizari!", Toast.LENGTH_SHORT).show();
String url = "http://grupovrt.ddns.net:81/v4.2.apk";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Virtual Romania Tv UPDATE");
request.setTitle("UPDATE Virtual Romania Tv");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Toast.makeText(getBaseContext(), "Descarc noi actualizari!", Toast.LENGTH_SHORT).show();
}
request.setDestinationInExternalPublicDir("/update", "v4.2.apk");
}else {
Toast.makeText(getBaseContext(), "Nu ai permisiunea sa descarci!", Toast.LENGTH_SHORT).show();
}