Can anybody tell which method calls, When I change permission of app from SETTINGS page ,When app is in minimized state.?
App Code :https://drive.google.com/file/d/0BxK5c-Q5uNaPOWJycFVtaThxWmc/view?usp=sharing
1)App asked for camera permssion
2)User Granted
3)App minimized
4)Go to setting -->apps -->revoke camera permission Now i need to know which method calls in activity or how to handle the recreation of activity.
NOTE :
Now What happened Presently is App getting Recreating again ,can anybody tell how to stop it.?
Related
I couldn't find any information about what happens when the user disables an app's permission while the app is running.
Is the application re-initilized?
I saw that in some apps if a Dialog or BottomSheet is open while I disable the permission, the dialog is no longer displayed when I return to the app.
Can anyone explain what happens in-detail when a permission is denied at runtime? Or does anyone have some useful links for me?
I would be especially interested in which lifecycle events are called when returning to the app.
When a previously granted permission is revoked through settings, the app is force stopped. You can see this by watching your app in the debugger. The app process is marked DEAD as soon as the permission is revoked.
Returning to the app will launch it from the main activity. I've never really looked into why this happens, but I assume it's because when a granted permission is revoked, the user could be deep into the app at a place where it is assumed the permission is granted. When the permission is revoked, there's no way to know if the screen they are currently in is even valid anymore.
Upon returning to the app, the app's state is restored and your current activity will be restarted, similar to a configuration change. If the activity you are in assumes a certain permission is granted, you should probably check that permission again in onCreate() to make sure you have it.
Simply put, That depends on what the app is trying to do when it needs permission.
For example: If we live in a country that requires you to be an adult to watch any video on YouTube, nothing will work with Location permissions denied
Another example: If you want to take photos using your phone via an app, the Camera permission should be permitted.
Under some circumstances, just part functions of app can not be used, but at an Extreme case, app would throw Security Exception and crash.
According to your point :
I saw that in some apps if a Dialog or BottomSheet is open while I
disable the permission, the dialog is no longer displayed when I
return to the app.
There is no lifecycle callback about what you do once permission is denied, but there's method on ActivityCompat which gives you flag if you want to show your own Dialog/BottomSheet
So, you can call shouldShowRequestPermissionRationale() method from ActivityCompat & make your own logic work when it's true.
shouldShowRequestPermissionRationale :
Gets whether you should show UI with rationale for requesting a permission. You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.
For example,
if you write a camera app, requesting the camera permission would be expected by the user and no rationale for why it is requested is needed.
If however, the app needs location for tagging photos then a non-tech savvy user may wonder how location is related to taking photos. In this case you may choose to show UI with rationale of requesting this permission.
While disabling permission for first time will give you callback in onRequestPermissionResult() method.
1)Create an app which ask for camera permission.
2)User grant the permission
3)Now minimize the app
4)Go to Setting -> Apps --> Your Application-->revoke the camera permission
5)Now activity getting created ,how to stop recreating .
I found this one but how i can achieve this
Application is getting killed after enable/disable permissions from settings on Android M nexus 6
I have an application with many activities. When I revoke the permission the application crashes in another Activity. I tried to debug the application and catch where the activity is breaking, but when the application is killed I canĀ“t continue to debug. My question is, is there a way to handle the permissions globally? Where in the activity I can check for permission? onStart? onCreate?Where in Activity I have to check for permission? Thanks in advance.
First, I'd like to thanks #CommonsWare and #nightlyrails, then like to explain how I resolved the question and expect your commentaries.
in method onCreate() checked if the savedInstanceBundle is null. If it is null the activity is just starting and everything is ok.
If the savedInstanceBundle is not null, I asked for permissions.
By doing this, I could prevent application from crash, everytime I revoked the permissions.
One more time, thanks for the tips.
I know, with Android Marshmallow, we have to ask permissions every time we need a functionality that require a permission.
I do this for new App, but for old BIG App is more complicated.
For old BIG App, I ask all permissions in "MainActivity".
So, my app is started and shows a Map Fragment.
I ask for Location Permission with no problem. The user agrees.
The user puts it in background, goes in the App Settings and denies permission.
Then he puts the App in foreground: App crashes!!
I know, there is a problem using Map Fragment.
But the App is too BIG to analyze every single permission.
I need the FAST solution: PERMISSION CHANGE ---> RESTART APP!!!
And this is what GoogleMaps does!
I started GoogleMaps, and put it in background.
GoogleMaps App permissions, the first difference:
in my App, if I denied a permission, I haven't this message showing for Google Maps:
Permission denied
After that, if I put GoogleMaps in foreground, the App restart with no problem:
GoogleMaps restart
I need this for my app. Can someone help me?!?!?!?
Thanks a lot!!
When permissions are revoked, your app is killed and restarted. Look on the logcat when you revoke permission with your application in background. You will see :
I/ActivityManager(572): Killing 13896:com.your.app/uxxxx (): permissions revoked
So you need to only check permissions in your class "myApplication extends Application" in the onCreate() function.
I have a live Wallpaper. This live wallpaper has a settings page implemented from PreferenceActivity. Everything works as expected. So far, so good.
From my Wallpaper Settings page..I want to start another activity (a details activity...with info, bitmaps, links, etc...). When I start this activity I get a security exception error:
java.lang.SecurityException: Permission Denial: starting Intent {... } from ProcessRecord ... requires android.permission.BIND_WALLPAPER
The manifest has the required permission. I've tried putting this permission everywhere .. even in multiple locations (not just in the service tag in the manifest). I'm starting the Activity from the wallpaper settings page with a new intent, then calling startActivity.
Does anyone know why I'm getting the permission denial even when the permission is included? Can someone tell me how to start the activity correctly without getting a force close?
Much appreciated.