Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android new permission model

894 views

Published on

Android new permission model in Kanmoba #7

Published in: Technology
  • Be the first to comment

Android new permission model

  1. 1. New Android Permission model @takuji31
  2. 2. About me • @takuji31 (Takuji Nishibayashi) • Fenrir Inc. • NNID: takuji31 • Udemae: S / Rank: 40 • Loves Android / Kotlin
  3. 3. Kotlin 1.0.0-beta released 🎉
  4. 4. Android 6.0 (Marshmallow) released 🎉
  5. 5. New features
  6. 6. Now on Tap
  7. 7. Fingerprint
  8. 8. New Permission model
  9. 9. targetSdkVersion >= 23
  10. 10. Normal permissions automatically granted
  11. 11. Danger permission needs request at runtime
  12. 12. Storage
  13. 13. Phone
  14. 14. Camera
  15. 15. Location
  16. 16. Calendar
  17. 17. Contacts
  18. 18. etc.
  19. 19. https://developer.android.com/intl/ja/guide/topics/ security/permissions.html#normal-dangerous
  20. 20. Permission grant flow
  21. 21. Check -> Request -> Grant
  22. 22. Check
  23. 23. 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
 }
  24. 24. Request
  25. 25. 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 );
 }
  26. 26. Grant
  27. 27. Check permission granted // In Activity @Override
 public 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
 }
 }
 }
  28. 28. see https://developer.android.com/training/ permissions/index.html

×