Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Marshmallow: permissions change for running app

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!!

like image 241
Michele Saccomanno Avatar asked Nov 18 '15 16:11

Michele Saccomanno


Video Answer


1 Answers

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.

like image 147
earlypearl Avatar answered Nov 15 '22 08:11

earlypearl