Home » Android » android – how to fix screen overlay detected programmatically

android – how to fix screen overlay detected programmatically

Posted by: admin June 15, 2020 Leave a comment

Questions:

In my app, I ask for permission to access SMS in Android SDK 23 (runtime permission) but the problem is dialog screen overlay showed up and access not granted .i disabled all another apps overlay but nothing changed.
I found this link but not helped

and the question is how can I fix it programmatically?

How to&Answers:

Ok,

finally I found the solution, I search all the web and can’t find anything useful.
The answer is: When you ask for new permission don’t ever do something else like showing toast or…. In my case I restart my app and ask for the next permission I use this code for restart the app.

Good luck.

Answer:

Here is your solution: https://gist.github.com/Aeonitis/2337b1ca652173839395be82db7d05c3

If you have any questions, let me know.

Answer:

Or you can delay your code execution by using postDelayed

(new Handler()).postDelayed(new Runnable() {
   @Override
   public void run() {
      // do something
   }
}, 500); // it doesn't hurt to wait 500ms is it?