Простое приложение которое должно скачивать другой apk файл, но оно выдает ошибку связанную с директорией и не скачивает файл
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.buratinoapps.wearstore/com.buratinoapps.wearstore.MainActivity}: java.lang.IllegalStateException: Unable to create directory: /storage/emulated/0/Download
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private String filepath = "http://test.ru/";
private URL url = null;
private String fileName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
innitView();
innitDownloaderFile();
//innitConnectedWearOs();
//innitDeleteApp();
}
private void innitView() {
try {
url = new URL(filepath);
} catch (MalformedURLException e) {
e.printStackTrace();
}
fileName = url.getPath();
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
binding.first.setText(fileName);
}
private void innitDownloaderFile() {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url + ""));
request.setTitle(fileName);
request.setMimeType("application/apk");
request.allowScanningByMediaScanner();
request.setAllowedOverMetered(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
}
Вот мой Манифест
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WearStore"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
tools:targetApi="31">