I'm use ActivityResultContracts to request runtime permissions. Here is my code:
private val contactsPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
// some logic here
}
And in onCreate():
contactsPermissionLauncher.launch(Manifest.permission.READ_CONTACTS)
Accordingly, I should be request for permission every time I go to the activity/fragment.
At first glance, everything works well. However, I noticed such a problem, on Android 11, after a certain number of times the permission was denied, when re-navigating to the screen, permission is not requested (that is, the system dialog is not displayed).
And also on android 6, it was noticed that after a lot of permission denial, after the next display of the system dialog asking for permission, when trying to allow, the button does not respond, while the deny button works correctly.
Can you please tell me what could be causing these problems? Perhaps there is a permission request limit?
Please, help me(
In the Google Play Console there is a very helpful page “Android vitals” / “ANRs & crashes”. The information provided under “crashes” is almost helpful (e.g. NullPointerException in "filename, line number"). That is something to work with. However, the info under “ANRs” (Activity Not Responding) is mostly mysterious.
For example, I have written an app which needs read/write access to the external storage – which is not necessarily a removable SD Card. Since Android 4.2 (API 17), access to the external SD Card is not possible any more. Instead, there is a link to “/mnt/sdcard” or "/storage/emulated/0", which resides in the internal memory. (Why this is called “external storage” is Google’s secret.)
Of course I have set the required entries in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
and of course, since Android 6 (Marshmallow), I am handling the permissions correctly with
requestPermissions(requPerms, myRequestCode);
and
onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
To determine the storage path for the app data files (for example "/storage/emulated/0"), I use the following code:
public static File getMountName()
{
File mount = null;
// possible ANR 1
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED))
{
// possible ANR 2
File path = Environment.getExternalStorageDirectory();
mount = new File(path.getAbsolutePath());
}
return mount;
} // getMountName
For some reason, some of the user’s smartphones are hanging with “ANR” in one of the two lines “Environment.getExternalStorage…” marked with the respective comment. (Which means, if they hang on the 2nd line, they have passed the 1st one successfully.)
The related error messages in Android vitals are shown in the following examples:
for ANR 1:
Input dispatching timed out (Waiting to send non-key event because the
touched window has not finished processing certain input events that
were delivered to it over 500.0ms ago. Wait queue length: 2. Wait
queue head age: 14805.0ms.)
and for ANR 2:
Context.startForegroundService() did not then call
Service.startForeground(): ServiceRecord{33def99 u0
net.braun_home.sensorrecording.lite/net.braun_home.sensorrecording.SensorService}
Does anybody have an idea, what these messages mean, and why they appear on some smartphones only? According to Android vitals, they all have newer Android versions 8 or 9. I myself have also two devices with these versions and the app runs perfectly there.
I'm trying to get the current location of the device using the plugin location but Android never asks for permissions. I get this error:
Exception has occurred. PlatformException
(PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission
denied forever- please open app settings, null))
I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I tried the plugin permission_handler to request them manually but still, no pop-up.
I'm completely lost and I find nothing similar on the net. Here is the code :
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28). I've also tried to uninstall/reinstall the app.
After asking on the git of location plugin, I did this :
flutter clean
And I got the pop up asking for permissions.
Thank to this guy.
You can handle this kind of permission behavior in your code. Even if you never had installed your app on emulator this behavior can happen and you must handle this in your code because this can happen when your app are in final user hands.
This exception means that you're getting PermissionStatus.denied from checkPermissionStatus permission handler plugin method and this can happen when user hits Never ask again checkbox in android permission dialog and deny the request.
What is the most simple way to handle this?
If you get PermissionStatus.denied from checkPermissionStatus method you can show a dialog telling to the user that your app needs of that permission to provide a better experience and in this dialog you can redirect the user to Android permission settings where the user can enable the requested permission manually.
You can do this using openAppSettings() method from permission handler plugin.
Maybe you should read this article, it's a little bit old but it shows the correct flow about how to ask and handle user permissions in android. This article doesn't talks about the new permissions changes in newer Android Q.
The error message tries to make it clear: Your device (you or someone else on the device you are testing on) has selected Never when Android asked for the permission previously.
This means that Android will not ask for the permission again.
Just try it on a different device or uninstall the app again.
add this
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
MIUI has a very weird issue related to Permissions, Pre Marshmallow the Device had the concept of Dynamic Permissions,which was good, we can simply call the method and OS took care of showing Alert for user to grant permission.
But Once the OS is Updated to Marshmallow it has issue displaying its custom Permission alert for some types (FILE_LOCATION) but not for all (CAMERA) ,
what I observed ,when I call
ActivityCompat.requestPermissions(startActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_FINE_LOCATION);
this
#Override
public void onRequestPermissionsResult()
Is being triggered even without User's selection with Result PERMISSION_GRANTED.
The real problem is not just that, I tried with many apps that was downloaded from PlayStore but they did not have any issue displaying the alert when location service is needed,
So is there any work around which can trigger the Dynamic permission in all cases regardless of device
This issue was fixed with the latest MIUI Rom update 6.4.14
I have Android Marshmallow on a Nexus 6. I am trying to fix the following problem:
If a user is trying to grant permission while a notification is showing, a "Screen overlay detected" message gets displayed and the Request Permission dialog disappears - of course the app does not get the requested permission. (Check screenshot)
I tried to fix the problem by adding "DRAW OVER OTHER APPS" permission - android.permission.SYSTEM_ALERT_WINDOW to the manifest but with no luck.
PS: I am sure the problem is caused by the notification. I do not have any app installed that overlays over other apps, I even turned off all apps with "Draw over other apps" permission in the settings. Did not help..
Anyone knows a solution to that problem?
In the circumstance that I ran across, I was causing the problem myself. It was the result of using a Toast to display information to the user at the same time that I was asking for permission. Both of these actions together cause this type of error.
The other answers might resolve someone else's issue. But I wanted to note that you should be cautious of causing your own overlays errors. Be careful of overlaying something in the view while simultaneously asking for permission.
Uninstall Clean Master app. I uninstalled it and problem solved
This problem appear because of some culprit application like Twilight, cleaner-master, drupe etc..
To solve this problem you have to disable screen overlay for those culprit apps.
i have moto g4 plus, and this is how i solve this problem
Go to Setting --> Select Apps ---> again select setting icon in Apps ---> select draw over other apps ---> and disable culprit apps who trouble for other apps.
what i done is checking each apps by disabling this permission and try to run my app, and i found one app this troubling overlay for other apps, so at the end i disabled only this app.
ScreenShots:
Got insights from multiple answers here and other forums .
Consolidating how I got rid of the issue :
Go to Settings > Apps > (your app which is getting issue)
Press on Power button till window for Power off , reboot , airplane mode comes up
Hold on Power off option
Select reboot in Safe mode
Go to settings > apps > (your app which is getting issue)
Select whichever permissions you want
After Android M update , issues can come up in apps like Messenger , Whatsapp , Prisma etc.
Let me know if any issues .
Note : I am having One plus One mobile.
This popup is caused by the manifest.PERMISSION.SYSTEM_ALERT_WINDOW permission declared by the manifest.
The are 3 categories of permissions, that developer must be aware of :
Normal permission - do nothing with them, just declare in the Manifest
Vulnerable permissions - declare in Manifest and ask for permission at first time. They can be changed through system settings.
Above dangerous permissions: SYSTEM_ALERT_WINDOW and WRITE_SETTINGS belong to this category. They must be granted, but are not visible in system settings. To request for it you don't use a standard way (int checkSelfPermission (String permission)) but you have to check Settings.canDrawOverlays() or Settings.System.canWrite() appropriately and if you not do that you will get exception like
Unable to add window android.view.ViewRootImpl$W#1de28ad -- permission denied for this window type
1-Request this permission by yourself in your code just like given below:
public class MainActivity extends AppCompatActivity {
public final static int REQUEST_CODE = 10000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkDrawOverlayPermission()) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
}
}
public boolean checkDrawOverlayPermission() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
} else {
return true;
}
}
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
}
}
}
I just deleted my app and turned off my Nexus 6P. After turning it back on, I reinstalled the app and no longer got the "screen overlay" dialogs when giving the app permissions.
You must disable the overlay for all the apps you see in the list. Only this way can you modify authorizations in the app you need.
I've done that in safe mode, and it worked.
At the end I rebooted the phone and now it is working fine.
I updated my Sony Xperia Z3 (Dual Sim) to Android 6.0.1 (Marsmallow). I have been having screen overlay issues. For me i do not have Clean Master, Du Speed, or Du Booster(as the solutions i have read).
So i solved mine looking for any screen overlay apps.
A screen overlap app, is an app that you can use to access other apps on your main home screen without leaving your home screen. So for me the Screen Overlay App here in my situation was the OMNI SWIPE. So if you are facing this problem you need to calm down and check which of your app fits the definition of a screen overlay app.
locate the app and uninstall then restart your phone ..
i just finished doing this and am having a good time with the phone
Best of Luck
As long as Android 6.x is buggy on some devices where this "overlay alert" is displayed without any reason (on 2 to 5% of the devices according to my analytics data), the best solution is to avoid the whole permission process by defining the targetSdk to 22.
Take care that you can't downgrade the target sdk for a new version or this will induce a INSTALL_FAILED_PERMISSION_DOWNGRADE error when the user updates requiring an unisntall/install of the app.
solution is
remove Toast messages from onRequestPermissionsResult method
This happens when you have granted overlay permission to malicious apps. Go to overlay settings and disable the overlay feature on all apps that don't belong to google and you will be good to go.
I got this problem when installing a new app.
The way I got around this problem is to manually enable the permissions for the newly installed app (before running the app).
I’m pretty sure this is a problem with Android and Samsung devices in particular.
Hope this helps
Delete the apps which have screen overlay like CM security, Clean Master, etc.
Even delete and try with Messenger (FB app) if needed.