How to use DownloadManager on Android 10? - android

I want to use DownloadManager on Android 10 to download files, and a download progress notification bar will appear.
I use the following code, which can be used normally on devices under Android 9 but not on Android 10 emulator (no error exception message appears). The download progress notification bar does not appear on the notification bar, but I notice This file appeared in the "Files" app of the system and was not downloaded because its raw size (bytes) is always -1.
How can I modify my code so that it can be used on Android 10, thank you very much!
var request = DownloadManager.Request(Uri.parse(downloadUrl))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, saveName)
} else {
request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveName)
}
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI
)
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
)
request.setTitle("TEST")
request.setDescription("TEST")
downloadManager.enqueue(request)
Screenshot of the system app "File"
Screenshot of the system app "File"2
From the test results, this problem may be a bug in the simulator, because I did not test this problem on real devices (Samsung s10, Samsung note9, Xiaomi 8, Google nexus6P), but I have no more real devices , So if you have this problem with other real devices, please let me know.

Related

queryIntentActivities returns zero on AVD while correct browser count on a real device

I have following code taken from How get list of web browsers in system supposed to return all browsers installed on a device.
This does not raise any error but browsersList size is zero on any AVD while works as expected on a real smart phone.
What am I missing?
Edit
Tested AVDs
Android 11 - DOESN'T WORK
Android 10 - Works
Tested Actual Devices
Android 10 - Works
Android 9 - Works
Android 8 - Works
Since I don't have an actual device with Android 11 not sure if the v11 is the problem. But it seems so.
val packageManager: PackageManager = this.getPackageManager()
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.aurl.com"))
val browsersList = packageManager.queryIntentActivities(
browserIntent,
PackageManager.MATCH_ALL
)
browsersList.forEach {
val packageName = it.activityInfo.packageName
}
There are new changes in android 11 in package visibility.
More info you can find in documentation:
https://developer.android.com/training/basics/intents/package-visibility

NotificationManager.setInterruptionFilter not work for certain phone

val notificationManager:NotificationManager = context.getSystemService(
Context.NOTIFICATION_SERVICE
) as NotificationManager
notificationManager.setInterruptionFilter(
NotificationManager.INTERRUPTION_FILTER_ALL
)
The code is simple, just change the InterruptionFilter, I'
ve already got the DoNotDisturb permission, and it works on emulator.
But when I tested on a real device (OnePlus3) which has the same system of the emulator (Android 7.1.1 API25 with Google services installed), it doesn't work. The code executed, no error, no changes which means it doesn't change the current filter from INTERRUPTION_FILTER_NONE to INTERRUPTION_FILTER_ALL.
What happended and how to fix it?

Android DownloadManager failing on HTTP 406 error

I am using DownloadManager to download video file from internet to Environment.DIRECTORY_MOVIES. File is being downloaded, and when the download finishes I get ACTION_DOWNLOAD_COMPLETE broadcast.
But when I check download status there i get STATUS_FAILED back with REASON 406, which should be HTTP Error 406 Not acceptable. Also DownloadManager automatically deletes that file so I am not able to access it any more.
Strange thing is that it works on most devices and this is happening on Sony D5503 with android 5.1.1.
Do you have any idea why this can happen please?

Samsung Galaxy S4 Not Displaying Push Notifications from Parse.com

We're about to launch a new app on iOS & Android, using Parse.com to provide the push notification service.
We've been testing on 5 devices internally: iPhone, iPad, Galaxy Tab, Galaxy S3, Galaxy S4
Here is an example of one of the pushes:
{ "deal_id": "ad60b089-6678-42d9-a503-3525d0c8c065", "alert": "Reliable Rentals has a new deal available. Check your favourites now!", "sound": "default", "action": "SS" }
On iPhone/iPad/GalaxyTab/S3, when the push is received it plays the default alert sound and presents the notification on screen.
But for some reason the S4 does not display the push OR play a sound. I can only think of 2 explanations:
1) there is something wrong with the Parse code above
2) there is some setting on the S4 device that has disabled push notifications either for this app or completely
I am not an expert in either area (Parse or Android) so was hoping the community might know what I can do to troubleshoot further.
PS - first time StackOverflow poster. If my question doesn't meet the requirements of this forum I do apologise. Happy to schooled on how/when to use this forum!
I think the reason why push is not displayed can be connected with customizing your push. Maybe try to modify your push data.
You put sound parameter and action parameter. Official Parse documentation says:
*alert: the notification's message.
*badge: (iOS only)
*sound: (iOS only)
*content-available: (iOS only)
*category: (iOS only)
*uri
*title: (Android, Windows 8, & Windows Phone 8 only)
Also go to applicaition list in setting in your phone and find your app.
There should be option: Notifications -> enabled.
Hope it will help.
Since it works on other android devices , i doubt it is your code that is causing the problem
It could be that your app is not allowed to show notifications , Check that "show notifications" is enabled in settings Settings->Apps->your_app .
So you can try send this example push message:
JSONObject data = new JSONObject("{\"alert\": \"Message\",
\"title\": \"New push!\"}");
ParsePush push = new ParsePush();
push.setChannel("Mets");
push.setData(data);
push.sendPushInBackground();

Android DownloadManager 'Download Requires Network' error

I'm using the DownloadManager to queue up some downloads I'm making but running into this issue when I specifically try to use the Mobile/4G connection. I'm using an Android 2.3.4 phone. My code is using the 2.3.3 API.
I'm doing the following command (I want to force the connection to use 4G/3G)
request.setAllowedNetworkTypes(Request.NETWORK_MOBILE);
Whenever it attempts to download however, it places the download in the DownloadManager listing but it forever remains in the status "In progress" and an error at the top lists the file name and the error "Download requires network."
When I investigate further and connected my device to see the logs in logcat, I see the following error when it attempts to download:
Aborting request for download 92: download was requested to not use the current network type
I have the following permissions:
android.permission.WRITE_OWNER_DATA
android.permission.READ_OWNER_DATA
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_STATE
Any ideas of what it could be? Am I still missing a permission? Is there another setting that I need to control to specify the use of the Network connection only?
EDIT:
I have tried this on a brand new Galaxy tablet and this is the behavior I notice using this device: When the wifi is on and connected, it fails to download when specifying to use the NETWORK_MOBILE. If the wifi is turned off or not connected, it has no problem using the 4G connection. I'm thinking this is a security feature being done by the device, can this be overidden?
I dont know how you are setting up your download manager but this is how ive used it in the pass.
private long enqueue;
private DownloadManager dm;
public void onClick(View view) {
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(
Uri.parse("File URL"));
enqueue = dm.enqueue(request);
}
public void showDownload(View view) {
Intent i = new Intent();
i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
startActivity(i);
}
This error occurs when you have no data connection (doesn't matter whether or not you are connected to wifi). You are allowed to specify NETWORK_MOBILE by itself, but it will throw you an error saying "Download Requires Network" if it tries to do the download when your data connection isn't currently working.
My advice to get a data connection again is to walk around until you get a connection again. I can tell when I have a data connection on my Droid Bionic phone because the top bar icons that say 4G LTE and the 4 bars turn blue instead of white.

Categories

Resources