Handling Android Marshmallow Run TIme Permissions in Hybrid Mobile Apps
a short tale of marshmallow madness, and the incredibly simple way to get runtime permissions going in your app. We’re using Meteor.JS but this will work wherever your cordova project lives.
Woops! All of sudden, and without warning, our production app no longer records audio. That’s literally the point of it, to record audio!
As I begun to warm my hands on the flames flickering from our clients head, “it must have been that last late night tweak I released without proper QA” i think, “or was it the second last?”. What it turned out to be, was a lack of attention to how android is changing, for the better.
Developing hybrid cross platform apps can be incredibly complex,while you’ve got a single codebase usually, you’ve also got multiple environments with multiple versions. Taking web tech to “device land”, is like turning a quaint frontier town shootout into an all out civil war.
Get Permission, theres no forgiveness here.
In the latest version of android, delightfully dubbed “Marshmallow”, Android introduces discrete runtime permissions, allowing users to accept permissions mid app experience, and presumably giving developers the brand spanking new job of handling app state when users say no.
Turns out this is easier than I thought initially, you can add this cordova plugin, and then check, and request these permissions anywhere in your android hybrid app.
For Meteor add it like this:
meteor add cordova:email@example.com
Then when invoking a function that requires device permissions:
Moral of the story, pay attention to each environment you build for carefully, none of them stand still, and neither should you.
Check this out, and if you’ve got a better way of handling run time permissions in Cordova please let me know!