0

I need the android-support-v4 that goes with Android Marshmallow because it's contain the object PermissionChecker and it's the only way to know (on Marshmallow and up) if a user has denied an app permission (like location for example).

I saw C:\Program Files (x86)\Embarcadero\Studio\18.0\lib\android\debug\android-support-v4.jar but I don't see any PermissionChecker inside C:\Program Files (x86)\Embarcadero\Studio\18.0\lib\android\debug\classes.dex so i guess it's an old support-v4 that it's used inside the classes.dex.

Is there any way to update the classes.dex to use instead the latest android-support-v4 ?

blong
  • 2,145
  • 13
  • 23
zeus
  • 12,173
  • 9
  • 63
  • 184
  • Am I to understand, then, that on Marshmallow you cannot use regular permission checking, as per the code in, say the second listing in my answer here: http://stackoverflow.com/a/39763742/2817399 or the second listing in my answer here: http://stackoverflow.com/a/39642846/2817399 ? – blong Sep 29 '16 at 12:13
  • @blong: To explain better: as it turns out, The targetSdkVersion in the manifest must be 23, mine is 22. If your target SDK is 23 (Android 6), all of the permissions (in your manifest) are disabled by default, whereas if your target SDK is 22 (Android 5.1) and your app is running on Android 6, all of the permissions are enabled by default when the user installs the app, and even if the user revokes the permissions later on, the mentioned API returns incorrect value (which is a bug in my opinion). – zeus Sep 29 '16 at 14:08

2 Answers2

1

Here's what I did:

Used Java2OP against the android-support-v4.jar file in C:\Users\Public\Documents\Embarcadero\Studio\18.0\PlatformSDKs\android-sdk-windows\extras\android\support\v4 (you may need to download the Android Support Library in the Extras section of Android SDK Manager) because the PermissionChecker exists in that jar.

Disabled android-support-v4.dex.jar in the Libraries node for the project.

Added the android-support-v4.jar (mentioned in step 1) to the project

Using TJPermissionChecker.JavaClass.checkSelfPermission now returns the correct result if the user has denied the permission (i.e. in Android 6 or above)

Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
0

On the off-chance the answer to my comment/question to the posted question is "Oh, I hadn't tried that" and that regular approach works just fine, here is a unit that does regular Android permission checking.

unit MiscU;

interface

function HasPermission(const Permission: string): Boolean;

implementation

uses
  FMX.Helpers.Android,
  Androidapi.Helpers,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.GraphicsContentViewText;

function HasPermission(const Permission: string): Boolean;
begin
  //Permissions listed at http://d.android.com/reference/android/Manifest.permission.html
{$IF RTLVersion >= 30}
  Result := TAndroidHelper.Context.checkCallingOrSelfPermission(
{$ELSE}
  Result := SharedActivityContext.checkCallingOrSelfPermission(
{$ENDIF}
    StringToJString(Permission)) =
    TJPackageManager.JavaClass.PERMISSION_GRANTED
end;

end.

I'll remove this answer if it transpires that I am simply unaware of certain aspects of the more modern Android releases and this listing is not at all relevant to the issue the asker is trying to solve.

blong
  • 2,145
  • 13
  • 23
  • thanks Blong ! the example is very good, but it's not work on marshmallow. In fact, it's by design, on marshmallow, an user can deny a particular permission for the app (like the location). But to keep backward compatibility, the app will not know that this permission was denied (because before marshmallow this was not possible, when we install the app, that app have all the permissions and user can't revoke them), instead the app will receive null or default value when it will call denied functionality. so to conclude if targetSdkVersion < 23 then checkSelfPermission will always return true – zeus Sep 29 '16 at 13:59
  • the only option to make your code work is to update targetSdkVersion to 23, but i don't know if it's compatible with Firemonkey (and Berlin). i start a new thread to ask about it : http://stackoverflow.com/questions/39772269/firemonkey-can-we-update-targetsdkversion-in-androidmanifest-template-xml – zeus Sep 29 '16 at 14:03