SlideShare a Scribd company logo
1 of 31
Download to read offline
Runtime
Permissions
Handling with
EasyPermissions
Android Sandbox
Android permissions model
System Resources
(Contacts, GPS, Bluetooth, SMS, Network.. etc.)
Permissions
Access Rules
Permissions protection levels
Normal permissions
Dangerous permissions
Signature permissions
Special permissions
Permissions protection levels
Normal permissions
Dangerous permissions
Signature permissions
Special permissions
WAKE_LOCK, BLUETOOTH,
ACCESS_NETWORK_STATE,
SET_TIME_ZONE, VIBRATE,
INTERNET, SET_WALLPAPER,
NFC.
Permissions protection levels
Normal permissions
Dangerous permissions
Signature permissions
Special permissions
CAMERA,
CONTACTS,
LOCATION, PHONE,
CALENDAR, SMS,
STORAGE, SENSOR
Permissions protection levels
Normal permissions
Dangerous permissions
Signature permissions
Special permissions
READ_VOICEMAIL,
WRITE_VOICEMAIL,
BIND_PRINT_SERVICE
Permissions protection levels
Normal permissions
Dangerous permissions
Signature permissions
Special permissions
WRITE_SETTINGS,
SYSTEM_ALERT_WINDOW
Requesting permissions
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.fancy.package.name">
<!-- Normal permssions -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application ...>
...
</application>
</manifest>
Requesting permissions
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.fancy.package.name">
<!-- Normal permssions -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application ...>
...
</application>
</manifest>
Requesting permissions
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.fancy.package.name">
<!-- Normal permssions -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application ...>
...
</application>
</manifest>
Requesting permissions
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.fancy.package.name">
<!-- Normal permssions -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application ...>
...
</application>
</manifest>
Install-time requests
(Android 5.1.1 or below)
Requesting permissions
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.fancy.package.name">
<!-- Normal permssions -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application ...>
...
</application>
</manifest>
Runtime requests (Android 6.0 or higher)
class PermissionActivity : AppCompatActivity(){
private fun readContacts() {
// Check whether the permission has already been granted
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.READ_CONTACTS)) {
// Show the explanation dialog
} else {
// No explanation needed, request the permission
ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.READ_CONTACTS), RC_READ_CONTACTS)
}
} else {
// Permission has already been granted, Do the contacts-related task you need to do.
}
}
}
Requesting permissions
Ref: https://developer.android.com/training/permissions/requesting.html
class PermissionActivity : AppCompatActivity(){
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
RC_READ_CONTACTS -> {
// If request is cancelled, the result arrays are empty.
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
// Permission was granted, yay! Do the contacts-related task you need to do.
} else {
// Permission denied, boo! Disable the functionality that depends on this permission.
}
return
}
...
else -> {
// Ignore all other requests.
}
}
}
}
Handling permissions request results
Ref: https://developer.android.com/training/permissions/requesting.html
EasyPermissions
EasyPermissions
❏ Open Source library by Google developers
❏ Simplify basic runtime permissions logic
❏ Works with Activities and Fragments
❏ Offers @AfterPermissionGranted annotation
❏ Offers control over rationale dialog
❏ Works with kotlin
❏ Great support community
EasyPermissions
class PermissionActivity : AppCompatActivity(){
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
RC_READ_CONTACTS -> {
// If request is cancelled, the result arrays are empty.
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
// Permission was granted, yay! Do the contacts-related task you need to do.
} else {
// Permission denied, boo! Disable the functionality that depends on this permission.
}
return
}
...
else -> {
// Ignore all other requests.
}
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(){
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this)
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this)
}
override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been granted
}
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(){
private fun readContacts() {
// Check whether the permission has already been granted
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.READ_CONTACTS)) {
// Show the explanation dialog
} else {
// No explanation needed, request the permission
ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.READ_CONTACTS), RC_READ_CONTACTS)
}
} else {
// Permission has already been granted, Do the contacts-related task you need to do.
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(){
private fun readContact() {
// Check whether the permission has already been granted
if (EasyPermissions.hasPermissions(context!!, Manifest.permission.READ_CONTACTS)){
// Permission has already been granted, Do the contacts-related task you need to do.
} else{
// Permission not granted, request it now
EasyPermissions.requestPermissions(this, R.string.read_contact_rationale, RC_CONTACTS_PERM,
Manifest.permission.READ_CONTACTS)
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(){
@AfterPermissionGranted(RC_CAMERA_AND_LOCATION)
private fun requestMultiplePermissionss() {
val perms = arrayOf(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION)
// Check whether the permission has already been granted
if (EasyPermissions.hasPermissions(this, *perms)){
// Permission has already been granted, Do the camera with location related task you need to do.
} else{
// Permissions not granted, request them now
EasyPermissions.requestPermissions(
PermissionRequest.Builder(this, RC_CAMERA_AND_LOCATION, *perms)
.setRationale(R.string.camera_and_location_rationale)
.setPositiveButtonText(R.string.rationale_ask_ok)
.setNegativeButtonText(R.string.rationale_ask_cancel)
.setTheme(R.style.my_fancy_style)
.build())
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this)
}
override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been granted
}
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
…
// Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
// This will display a dialog directing them to enable the permission in app settings.
AppSettingsDialog.Builder(this).build().show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
// Do something after user returned from app settings screen, like showing a Toast.
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
…
// Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
// This will display a dialog directing them to enable the permission in app settings.
AppSettingsDialog.Builder(this).build().show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
// Do something after user returned from app settings screen, like showing a Toast.
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
…
// Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
// This will display a dialog directing them to enable the permission in app settings.
AppSettingsDialog.Builder(this).build().show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
// Do something after user returned from app settings screen, like showing a Toast.
}
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks {
override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been granted
}
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
}
override fun onRationaleDenied(requestCode: Int) {
// Some permissions rationale denied
// ...
}
override fun onRationaleAccepted(requestCode: Int) {
// Some permissions rationale accepted
// ...
}
}
EasyPermissions
class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks {
override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been granted
}
override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) {
// Some permissions have been denied
}
override fun onRationaleDenied(requestCode: Int) {
// Some permissions rationale denied
// ...
}
override fun onRationaleAccepted(requestCode: Int) {
// Some permissions rationale accepted
// ...
}
}
EasyPermissions
DEMO
References
Android app permissions:
https://developer.android.com/guide/topics/permissions/index.html
EasyPermissions
https://github.com/googlesamples/easypermissions
Demo
https://github.com/GDG-Trondheim/runtimepermissions
Thank You
Q&A
twitter.com/ernestkamara | ernest@kamara.io | www.kamara.io

More Related Content

Similar to Runtime permissions handling with easy permissions

What is new in Android M
What is new in Android MWhat is new in Android M
What is new in Android MErik Hellman
 
Android RuntimePermissionsExtended
Android RuntimePermissionsExtendedAndroid RuntimePermissionsExtended
Android RuntimePermissionsExtendedNebojša Vukšić
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
Sample APK Analysis 4 - 55688
Sample APK Analysis 4 - 55688Sample APK Analysis 4 - 55688
Sample APK Analysis 4 - 55688Lin BH
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
Role based access control
Role based access controlRole based access control
Role based access controlPeter Edwards
 
F2F 2015 - Client SDK (Specific Plataform Android)
F2F 2015 - Client SDK (Specific Plataform Android)F2F 2015 - Client SDK (Specific Plataform Android)
F2F 2015 - Client SDK (Specific Plataform Android)Daniel Passos
 
Step-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformStep-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformEric Vétillard
 
Understanding Active Directory Enumeration
Understanding Active Directory EnumerationUnderstanding Active Directory Enumeration
Understanding Active Directory EnumerationDaniel López Jiménez
 
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...RootedCON
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityJoris Kuipers
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)James Titcumb
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsAleksandar Ilić
 

Similar to Runtime permissions handling with easy permissions (20)

What is new in Android M
What is new in Android MWhat is new in Android M
What is new in Android M
 
Android RuntimePermissionsExtended
Android RuntimePermissionsExtendedAndroid RuntimePermissionsExtended
Android RuntimePermissionsExtended
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
My name is Trinidad
My name is TrinidadMy name is Trinidad
My name is Trinidad
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Sample APK Analysis 4 - 55688
Sample APK Analysis 4 - 55688Sample APK Analysis 4 - 55688
Sample APK Analysis 4 - 55688
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Role based access control
Role based access controlRole based access control
Role based access control
 
F2F 2015 - Client SDK (Specific Plataform Android)
F2F 2015 - Client SDK (Specific Plataform Android)F2F 2015 - Client SDK (Specific Plataform Android)
F2F 2015 - Client SDK (Specific Plataform Android)
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Step-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformStep-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected Platform
 
Java RMI
Java RMIJava RMI
Java RMI
 
Understanding Active Directory Enumeration
Understanding Active Directory EnumerationUnderstanding Active Directory Enumeration
Understanding Active Directory Enumeration
 
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...
Daniel Kachakil - Android's Download Provider: Discovering and exploiting thr...
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring Security
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 

Recently uploaded

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 

Recently uploaded (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 

Runtime permissions handling with easy permissions

  • 2. Android Sandbox Android permissions model System Resources (Contacts, GPS, Bluetooth, SMS, Network.. etc.) Permissions Access Rules
  • 3. Permissions protection levels Normal permissions Dangerous permissions Signature permissions Special permissions
  • 4. Permissions protection levels Normal permissions Dangerous permissions Signature permissions Special permissions WAKE_LOCK, BLUETOOTH, ACCESS_NETWORK_STATE, SET_TIME_ZONE, VIBRATE, INTERNET, SET_WALLPAPER, NFC.
  • 5. Permissions protection levels Normal permissions Dangerous permissions Signature permissions Special permissions CAMERA, CONTACTS, LOCATION, PHONE, CALENDAR, SMS, STORAGE, SENSOR
  • 6. Permissions protection levels Normal permissions Dangerous permissions Signature permissions Special permissions READ_VOICEMAIL, WRITE_VOICEMAIL, BIND_PRINT_SERVICE
  • 7. Permissions protection levels Normal permissions Dangerous permissions Signature permissions Special permissions WRITE_SETTINGS, SYSTEM_ALERT_WINDOW
  • 8. Requesting permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.fancy.package.name"> <!-- Normal permssions --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Dangerous permissions --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application ...> ... </application> </manifest>
  • 9. Requesting permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.fancy.package.name"> <!-- Normal permssions --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Dangerous permissions --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application ...> ... </application> </manifest>
  • 10. Requesting permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.fancy.package.name"> <!-- Normal permssions --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Dangerous permissions --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application ...> ... </application> </manifest>
  • 11. Requesting permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.fancy.package.name"> <!-- Normal permssions --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Dangerous permissions --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application ...> ... </application> </manifest> Install-time requests (Android 5.1.1 or below)
  • 12. Requesting permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.fancy.package.name"> <!-- Normal permssions --> <uses-permission android:name="android.permission.INTERNET"/> <!-- Dangerous permissions --> <uses-permission android:name="android.permission.READ_CONTACTS"/> <application ...> ... </application> </manifest> Runtime requests (Android 6.0 or higher)
  • 13. class PermissionActivity : AppCompatActivity(){ private fun readContacts() { // Check whether the permission has already been granted if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.READ_CONTACTS)) { // Show the explanation dialog } else { // No explanation needed, request the permission ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.READ_CONTACTS), RC_READ_CONTACTS) } } else { // Permission has already been granted, Do the contacts-related task you need to do. } } } Requesting permissions Ref: https://developer.android.com/training/permissions/requesting.html
  • 14. class PermissionActivity : AppCompatActivity(){ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { when (requestCode) { RC_READ_CONTACTS -> { // If request is cancelled, the result arrays are empty. if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) { // Permission was granted, yay! Do the contacts-related task you need to do. } else { // Permission denied, boo! Disable the functionality that depends on this permission. } return } ... else -> { // Ignore all other requests. } } } } Handling permissions request results Ref: https://developer.android.com/training/permissions/requesting.html
  • 16. EasyPermissions ❏ Open Source library by Google developers ❏ Simplify basic runtime permissions logic ❏ Works with Activities and Fragments ❏ Offers @AfterPermissionGranted annotation ❏ Offers control over rationale dialog ❏ Works with kotlin ❏ Great support community
  • 17. EasyPermissions class PermissionActivity : AppCompatActivity(){ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { when (requestCode) { RC_READ_CONTACTS -> { // If request is cancelled, the result arrays are empty. if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) { // Permission was granted, yay! Do the contacts-related task you need to do. } else { // Permission denied, boo! Disable the functionality that depends on this permission. } return } ... else -> { // Ignore all other requests. } } } }
  • 18. EasyPermissions class PermissionActivity : AppCompatActivity(){ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) // Forward results to EasyPermissions EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this) } }
  • 19. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) // Forward results to EasyPermissions EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this) } override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) { // Some permissions have been granted } override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied } }
  • 20. EasyPermissions class PermissionActivity : AppCompatActivity(){ private fun readContacts() { // Check whether the permission has already been granted if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.READ_CONTACTS)) { // Show the explanation dialog } else { // No explanation needed, request the permission ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.READ_CONTACTS), RC_READ_CONTACTS) } } else { // Permission has already been granted, Do the contacts-related task you need to do. } } }
  • 21. EasyPermissions class PermissionActivity : AppCompatActivity(){ private fun readContact() { // Check whether the permission has already been granted if (EasyPermissions.hasPermissions(context!!, Manifest.permission.READ_CONTACTS)){ // Permission has already been granted, Do the contacts-related task you need to do. } else{ // Permission not granted, request it now EasyPermissions.requestPermissions(this, R.string.read_contact_rationale, RC_CONTACTS_PERM, Manifest.permission.READ_CONTACTS) } } }
  • 22. EasyPermissions class PermissionActivity : AppCompatActivity(){ @AfterPermissionGranted(RC_CAMERA_AND_LOCATION) private fun requestMultiplePermissionss() { val perms = arrayOf(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION) // Check whether the permission has already been granted if (EasyPermissions.hasPermissions(this, *perms)){ // Permission has already been granted, Do the camera with location related task you need to do. } else{ // Permissions not granted, request them now EasyPermissions.requestPermissions( PermissionRequest.Builder(this, RC_CAMERA_AND_LOCATION, *perms) .setRationale(R.string.camera_and_location_rationale) .setPositiveButtonText(R.string.rationale_ask_ok) .setNegativeButtonText(R.string.rationale_ask_cancel) .setTheme(R.style.my_fancy_style) .build()) } } }
  • 23. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) // Forward results to EasyPermissions EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this) } override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) { // Some permissions have been granted } override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied } }
  • 24. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied … // Check whether the user denied any permissions and checked "NEVER ASK AGAIN." if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // This will display a dialog directing them to enable the permission in app settings. AppSettingsDialog.Builder(this).build().show() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) { // Do something after user returned from app settings screen, like showing a Toast. } } }
  • 25. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied … // Check whether the user denied any permissions and checked "NEVER ASK AGAIN." if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // This will display a dialog directing them to enable the permission in app settings. AppSettingsDialog.Builder(this).build().show() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) { // Do something after user returned from app settings screen, like showing a Toast. } } }
  • 26. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks { override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied … // Check whether the user denied any permissions and checked "NEVER ASK AGAIN." if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // This will display a dialog directing them to enable the permission in app settings. AppSettingsDialog.Builder(this).build().show() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) { // Do something after user returned from app settings screen, like showing a Toast. } } }
  • 27. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks { override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) { // Some permissions have been granted } override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied } override fun onRationaleDenied(requestCode: Int) { // Some permissions rationale denied // ... } override fun onRationaleAccepted(requestCode: Int) { // Some permissions rationale accepted // ... } }
  • 28. EasyPermissions class PermissionActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks { override fun onPermissionsGranted(requestCode: Int, perms: MutableList<String>) { // Some permissions have been granted } override fun onPermissionsDenied(requestCode: Int, perms: MutableList<String>) { // Some permissions have been denied } override fun onRationaleDenied(requestCode: Int) { // Some permissions rationale denied // ... } override fun onRationaleAccepted(requestCode: Int) { // Some permissions rationale accepted // ... } }
  • 31. Thank You Q&A twitter.com/ernestkamara | ernest@kamara.io | www.kamara.io