1

Is it possible to run Google Sample - RuntimePermissionsBasic

On devices with OS less than MNC (Android M)?

This project comes with:

compileSdkVersion "android-MNC"
targetSdkVersion "MNC"

So far so good, running it on less than M OS will get:

INSTALL_FAILED_OLDER_SDK

But when I changed it to:

compileSdkVersion 22
targetSdkVersion "MNC"

The Android Studio isn't recognizing the checkSelfPermission (...) method

David
  • 36,027
  • 32
  • 117
  • 140

2 Answers2

5

Try to add ContextCompat.checkSelfPermission() instead just checkSelfPermission...for me it works...

Olumide
  • 758
  • 13
  • 30
Alexiscanny
  • 573
  • 7
  • 15
2

So far so good, running it on less than M OS will get: INSTALL_FAILED_OLDER_SDK

That is because setting compileSdkVersion to android-MNC forces the minSdkVersion to MNC by default. There are recipes for changing that behavior.

But when I changed it to... The Android Studio isn't recognizing the checkSelfPermission (...) method

checkSelfPermission() was introduced in the M Developer Preview and does not exist on older versions of Android.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367
  • @David: The code appears to be set up to support older devices (see the implementation and use of `isMNC()` in `MainActivity`), but the build process does not support it by default. As noted in my answer, there are workarounds to get the app to be able to run on older devices. – CommonsWare Jun 29 '15 at 16:31
  • 1
    Yes... the isMNC() was the confusing part for me. 10x, I will check the workarounds. – David Jun 29 '15 at 16:39
  • The only issue with that workaround is that the app will always think that the permission has been granted. Even on M devices. – David Jun 29 '15 at 17:32
  • @David: The build process workaround that I linked to is simply for testing purposes. AFAIK, this sample app is demonstrating how to request permissions, not the best practices for when and why to request permissions. – CommonsWare Jun 29 '15 at 17:57