android 10 : android.process.media keeps stopping when invoke downloadmanager - android

Recently I start testing my app in Android 10 (it works fine on the previous version). When I invoke download manager for a file, I got a crash with a message:
android.process.media keeps stopping
This is my snippet code:
String mFilePath = "file://"
+ FileManager.getInstance(getApplicationContext()).getDir()
+ "/"
+ fileName
+ extension;
Uri downloadUri = Uri.parse(fileUrl);
DownloadManager.Request req = new DownloadManager.Request(downloadUri);
req.setDestinationUri(Uri.parse(mFilePath));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(req);
What's the exact problem? How can I report this error to Gooogle?

Related

How does the Android Downloadmanager work?

I'm trying to download a file to the files-folder of the app
/data/user/0/app-name/files/
If I enqueue the download, the app crashes and I don't know why.
Trying setDestinationUri() AND setDestinationInExternalPublicDir() both won't work.
What is the big mistake?
DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("https://testpage.com/download.php");
DownloadManager.Request request = new DownloadManager.Request(uri);
//File fileDl = new File(getApplicationContext().getFilesDir() + "/");
String dFolder = getFilesDir().toString();
request.setDestinationUri(Uri.parse("file://" + dFolder + "/"));
//request.setDestinationInExternalPublicDir(fileDl + "/", "epaper.pdf");
downloadmanager.enqueue(request);
I know some of you can see the misunderstanding, but as a Newbie I'm blind :-)
Can anybody help?
Thx,
Chris

How to prevent application file deleted when uninstall the app in android

DownloadManager mgr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(file_url);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setTitle("")
.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/MyApp", tsLong.toString() + ".jpg");
The path to download file is here:
new File(Environment.DIRECTORY_PICTURES + "/MyApp")
I found that once the app is uninstall the folder is also deleted, how to preserve that ?
thanks a lot.

Show On Going Download progress in a RecyclerView in Android

I am currently working on app where you can download video files. I am using Download manager for downloading files and everything is working fine as the files are being downloaded properly and I can see the progress of downloading in my notifications. Now I want to show those downloading files in another class (containing recyclerview) with the progress. So what should i do to implement this module?
Currently my downloading file code is:
public static long fileDownloader(Activity context, Video video) {
File direct = new File(Environment.getExternalStorageDirectory()
+ "/FWV Videos");
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(video.getVideoURL());
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false).setTitle(video.getName())
.setDescription("Downloading file...")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setVisibleInDownloadsUi(false)
.setDestinationInExternalPublicDir("/FWV Videos", video.getName() + ".mp4")
.allowScanningByMediaScanner();
Toast.makeText(context, "Download started", Toast.LENGTH_SHORT).show();
return mgr.enqueue(request);
}
I just want a separate list where i can show on going downloads and completed downloads

How to detect the extension of file to download using DownloadManager in Android?

I start developing my very first Android project. In my project, I need to download media files, especially mp3 or mp4. I am downloading file using DownloadManager.
Here is my download code for mp3
private void downloadPodcast(int id)
{
String url = context.getResources().getString(R.string.api_endpoint)+"podcast/download?id="+String.valueOf(id);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading...");
request.setTitle("Podcast");
request.setMimeType("audio/MP3");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "audio.mp3");
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
As you can see in my code, I am downloading only mp3 and setting the MIME type is constant. The file name and its extension is constant as well. What I want to do is to detect the file extension I will download. So can I set the MIME type programmatically and set the extension of file name. How can I achieve it in DownloadManager?
Though its quite late, however here is the answer:
You can get the extension of the file to download using the code below and add the extension to your file name.
String fileUrl = "http://someurl";
String fileName = "foobar";
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(fileUrl);
// concatinate above fileExtension to fileName
fileName += "." + fileExtension;
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileUrl))
.setTitle(context.getString(R.string.app_name))
.setDescription("Downloading " + fileName)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(request);

download manager class crashes when try to download multiple files?

i am trying to download images from the web when my app is connected to the internet through this code
public void downloadimages(String url,String filename)
{
String ur1=url,v1=filename;
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse(ur1);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setDescription("Android Data download using DownloadManager.");
request.setDestinationInExternalFilesDir(getApplicationContext(),Environment.DIRECTORY_DOWNLOADS,v1 + ".jpg");
downloadManager.enqueue(request);
}
when i run the app first time downloads happen but the app crashes after that the app did'nt open i am checking for the dowloaded files also:
String path = "/mnt/sdcard/Android/data/com.example.webdata/files/Download/" + extra2 + ".jpg";
tt1.append(path);
File f = new File(path);
if(f.exists())
{
//Toast.makeText(getApplicationContext(), "File already exists....",
// Toast.LENGTH_SHORT).show();
}
else
{
downloadimages(extra,extra2);
}
if the file has been downloaded previously it should not be dowloaded next time ,but i my app crashes and i don't know why any help guys.........
this is my logcat output:-
02-21 18:00:41.547: E/AndroidRuntime(23964): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.webdata/com.example.webdata.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 1088, size is 1088
Can you show us the code MainActivity class, because it seems that the error comes from this class.
then the error is a IndexOutOfBoundsException, so have you tried with less image eg 10 or 20? and run later when the first 10 are recovered?

Categories

Resources