android new permission model
TRANSCRIPT
New Android Permission model@takuji31
About me
• @takuji31 (Takuji Nishibayashi)
• Fenrir Inc.
• NNID: takuji31
• Udemae: S / Rank: 40
• Loves Android / Kotlin
Kotlin 1.0.0-beta released 🎉
Android 6.0 (Marshmallow) released 🎉
New features
Now on Tap
Fingerprint
New Permission model
targetSdkVersion >= 23
Normal permissions automatically granted
Danger permission needs request at runtime
Storage
Phone
Camera
Location
Calendar
Contacts
etc.
https://developer.android.com/intl/ja/guide/topics/security/permissions.html#normal-dangerous
Permission grant flow
Check -> Request -> Grant
Check
Check permission status
// In Activity int permission = ContextCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE );
if (permission != PackageManager.PERMISSION_GRANTED) { // not granted} else { // granted or pre-Marshmallow}
Request
Request permission
if ( ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) ) { // should show rationale} else { // needs request permission ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE );}
Grant
Check permission granted
// In Activity @Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PERMISSION_REQUEST_CODE) { int grantResult = grantResults[0]; String statusString = toStatusString(grantResult); statusTextView.setText(statusString); if ( grantResults.length > 0 && grantResult == PackageManager.PERMISSION_GRANTED ) { // granted } else { // not granted } }}
see https://developer.android.com/training/permissions/index.html