I want to use ACTION_OPEN_DOCUMENT on my Xiaomi Device. I tried
this google sample, but it also not working. With code below i can normally run on Samsung galaxy s4.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);
Im getting "android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT_TREE }" error.
Xiaomi screwed up, apparently. AFAIK, they're not Google Play certified, so they do not need to pass the CTS. There is nothing you can really do about it, other than to detect this case (e.g., use PackageManager and queryIntentActivities(), or catch the ActivityNotFoundException) and fall back to whatever you do on pre-Android 4.4 devices.
I saw the same error occur on Xiaomi MI 6X with Android 10.
Upon some digging I realized that some devices allow the user to disable the "Files" app from Google Play Services (or might even do that by default). Thus, I would recommend first prompting user for enabling "Files" app and/or updating the Google Play Services. Please note, that on most devices the "Files" app is hidden from the user, thus it will not be present on app list in preferences.
Related
I recently updated my Poco X3 NFC 64GB test device to Android 11:
MIUI Global 12.0.8(RJGEUXM)
Android 11 RKQ1.200826.002
Ever since I am unable to take or pick photos in my app. On other Android 11 devices (and emulator) everything works fine. The app is compiled to API level 30.
I start the photo picker chooser like this:
private void pickPhoto() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent, 100);
}
}
This works fine, but after I have picked a photo it returns to the app, triggering onActivityResult with resultCode 0 (RESULT_CANCELED) and data is null too. On other Android 11 devices I can retrieve the photo from the data, but not on my Poco. Yes I did add the necessary query to the manifest file (else I wouldn't be able to open the picker in the first place).
When I try to fetch a photo from the camera I have exactly the same issue. Again on other Android 11 devices this works fine. So yes I did add and use the necessary file provider.
Sometimes a toast pops up about not having granted the right permissions. Do any of you guys have a Poco phone and like to try it out? I wonder if the Poco rom is just broken or something.
UPDATE
I've narrowed down the problem. It turns out that if startActivity() starts a camera/gallery activity directly it works fine. However if you're prompted a chooser first (e.g. because you have multiple gallery apps) it goes wrong.
So if you pick a gallery app and say to always use it in the future, the next time it will open that gallery app directly and then it works correctly.
If you use Intent.createChooser() it never works right. Even if it contains only one intent that is launched directly without prompting a chooser it fails to return a photo.
Can we agree that this is a MIUI bug?
Samsung Galaxy has the feature to put apps to sleep - which to my understanding is not the same as battery optimization for apps.
I need to programmatically check if an app is configured to sleep so I can properly warn the user about this and the fact that background tasks won't work.
I am aware of PowerManager.isIgnoringBatteryOptimizations() which however does not seem to be related to putting an app to sleep or not.
The thing with Samsung sleep feature is that it 'differs' from 'background optimizations'. Their feature is designed to freeze apps(just like freeze in the settings) after 3 days, but depending on user preference, it can be extended to 7 days. Currently, there is no known way to programmatically check if the app has been put to sleep.
What you can do is to inform the user about this and ask to 'whitelist' the app from imminent sleeping.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.samsung.android.sm", "com.samsung.android.sm.ui.battery.BatteryActivity"));
try {
getActivity().startActivity(intent);
} catch (ActivityNotFoundException exception) {
//Manager not installed
}
Code source
This code will try to open BatteryManager, from there, a user can select options to prevent from app sleeping.
Here are the relevant questions:
How do I check that my app enters optimizations Samsung devices?
Samsung “App optimization” feature kills background applications after 3 days
This blog should help you in figuring out the ways to inform the user about the issue
My application performs data synchronization in background service which is critical task for application in order to work properly. now, application works fine & expected in some of devices having pure Android or near to pure Android ROM. e.g. Google Nexus, Android One & Motorola devices. but, some devices like Redmi having MIUI has inbuilt options for blocking application's background processes. which causes my application working not properly. So, I want to know "is there any way to find out my background processes are blocked? so that I can notify user to unblock it."
here's a somewhat related question
here's some screenshot related to this.
Any suggestions or help are welcome.
Thanks in advance
as i know, apps cannot get the info about whether or not in whitelist, but you can notify the user any more by :
Intent intent = new Intent(); intent.setAction("miui.intent.action.OP_AUTO_START"); intent.addCategory(Intent.CATEGORY_DEFAULT);
I need to develop a Wallpaper application for Nook Color. I have installed the Nook color addon after that when i use this code in my app and it gets crashed every time. The below API Intent to allow any application to open the Wallpaper Settings Manager UI in Nook Color device
Intent i = new Intent();
i.setAction( "com.bn.nook.CHANGE_WALLPAPER" );
startActivity( i );
Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.bn.nook.CHANGE_WALLPAPER }
Please help, Thanks in advance.
This intent is only going to be available on Nook device.
Using this on any other device or emulator that isn't specifically designed to be the nook isn't going to work.
It would be like trying to open Internet Explorer on a machine which doesn't have Internet Explorer installed.
The code you have posted is a direct copy paste from (i assume) the official Nook Developer page here.
The code isn't inherently wrong, the Action your specifying simply doesn't seem to exist - you need to find the correct Action name from the Developers/Nook API.
I implemented a BroadcastReceiver for the Android Market INSTALL_REFERRER Intent as
described here:
Get referrer after installing app from Android Market
It works fine for android devices earlier than 3.0 but it never seems to fire on Honeycomb devices. I've checked the logcat output during the install and after the app's first launch and I don't see any of my debug output which leads me to believe that the BroadcastReceiver isn't being run (I do see the output on pre-Honeycomb versions).
Can anyone out there confirm this problem?
Any idea how to make it work?
There's a new flag called FLAG_EXCLUDE_STOPPED_PACKAGES in 3.1:
If set, this intent will not match any components in packages that are currently stopped. If this is not set, then the default behavior is to include such applications in the result.
From the release notes for 3.1:
Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents.
And also:
Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).
Seems like this is breaking the behavior of INSTALL_REFERRER in 3.1+ devices as your app has not yet been launched and so can not receive the broadcast. Sadly I don't know of any way to make this work. Google could probably do something to fix this in their Market app (one way would be to just use FLAG_INCLUDE_STOPPED_PACKAGES though I'm not sure that would be a great idea, given the whole point of these new launch controls).
As i experienced the Broadcast Intent *INSTALL_REFERRER* is fired once before the Application is launched the first time If you don't catch it there, you'll never get it again