Page 1 of 1

Declare Android app permissions

Posted: Tue Sep 26, 2017 8:07 pm
by Gurgen
Hi,

I'm trying to wrap android fingerprint API. For first I've tried to wrap the simplest method - isHardwareDetected. https://developer.android.com/reference ... Detected()

Documentation says that to use this class I need to grant a permission - USE_FINGERPRINT, so I've used the metadata declaration way from LC DP7 Release Notes.
metadata android.features is "hardware.fingerprint"
metadata android.hardware.fingerprint.required is "true"
metadata android.permissions is "USE_FINGERPRINT"
Everything seems to be easy, but while installing, android saying there is no permission required. And also the app crashes when I'm calling isHardwareDetected() method.

Please help to move forward.
Here is the LCB code.

Code: Select all

library com.livecode.library.androidfingerprint

use com.livecode.foreign
use com.livecode.java

metadata title is "AndroidFingerprint"
metadata author is "Livecode"
metadata version is "1.0.0"

metadata android.features is "hardware.fingerprint"
metadata android.hardware.fingerprint.required is "true"
metadata android.permissions is "USE_FINGERPRINT"

foreign handler _isHardwareDetected()returns JBoolean binds to "java:android.hardware.fingerprint.FingerprintManager>isHardwareDetected()Z"

public handler isfingerprintHardwareDetected() returns Boolean
   unsafe
      return _isHardwareDetected()
   end unsafe
end handler


end library

Thanks,
Gurgen

Re: Declare Android app permissions

Posted: Wed Sep 27, 2017 3:55 pm
by livecodeali
Hi Gurgen,
You need to obtain an instance of the fingerprint service and call isHardwareDetected on it - it's not a static method (and if it were you would need to add !static to the binding string).

You can use the getSystemService method to obtain such an instance - the following code works here:

Code: Select all

library com.livecode.library.androidfingerprint

use com.livecode.foreign
use com.livecode.java

metadata title is "AndroidFingerprint"
metadata author is "Livecode"
metadata version is "1.0.0"

metadata android.features is "hardware.fingerprint"
metadata android.hardware.fingerprint.required is "true"
metadata android.permissions is "USE_FINGERPRINT"

__safe foreign handler _JNI_GetAndroidEngine() returns JObject \
	binds to "java:com.runrev.android.Engine>getEngine()Lcom/runrev/android/Engine;!static"
__safe foreign handler _JNI_GetEngineContext(in pEngine as JObject) returns JObject \
	binds to "java:android.view.View>getContext()Landroid/content/Context;"

__safe foreign handler _JNI_GetSystemService(in pContext as JObject, in pService as JString) returns JObject \
    binds to "java:android.content.Context>getSystemService(Ljava/lang/String;)Ljava/lang/Object;"

__safe foreign handler _isHardwareDetected(in pService as JObject) returns JBoolean \
    binds to "java:android.hardware.fingerprint.FingerprintManager>isHardwareDetected()Z"

public handler isfingerprintHardwareDetected() returns Boolean
    variable tContext as JObject
    put _JNI_GetEngineContext(_JNI_GetAndroidEngine()) into tContext
    
    
    variable tService as JObject
    put _JNI_GetSystemService(tContext, StringToJString("fingerprint")) into tService
    
    return _isHardwareDetected(tService)
end handler


end library
Good luck, and let us know how you get on!
Cheers,
Ali

Re: Declare Android app permissions

Posted: Wed Sep 27, 2017 4:53 pm
by Gurgen
Thank you Ali for your effort. I highly appreciate your help.

Now the external works. Next I will try to wrap other methods and will update this thread.

Regards,
Gurgen