codename one: how do we scan fingerprints upto three times if fingerprint failed to scan? - codenameone

It's not working properly.I want to scan finger print on form open.On successful finger print scan "Home" form should open and on failed it should scan finger print again three times until successful scan and after successive three failed scans it should go to "Login" form for asking credential. In my case it working differently on different devices.On older android OS it's working partially. On latest android OS failed message comes three time before finger print scan. Please help me to solve this problem. Thanks in advance.
int fingerPrintCounter=0;
#Override
protected void postFinerPrint(Form f) {
while(fingerPrintCounter<3){
fingerPrintCounter++;
fingerPrintScanner(); //finger print scanner method
}
if(!fingerPrintStatus)
{
showForm("Login", null);
}
}
private void fingerPrintScanner() {
if (!Fingerprint.isAvailable()) {
fingerPrintCounter=3;
showForm("Login", null);
} else {
Fingerprint.scanFingerprint("Use your finger print", value -> {
fingerPrintCounter=3;
showForm("Home",null)
}, (sender, err, errorCode, errorMessage) -> {
if (Dialog.show("SCAN FAILED", "Please try again", "OK", null)) {
fingerPrintStatus=false;
}
}, false);
}
}

The fingerprint retries and security pin fallback are builtin to the low level native API we use. Looking at this briefly I didn't spot a way to block the pin fallback behavior as it's builtin to the native code.
This is our implementation code for Android https://github.com/codenameone/FingerprintScanner/blob/master/native/android/com/codename1/fingerprint/impl/InternalFingerprintImpl.java
Looking at the native code it doesn't seem like they provide an option to control this but maybe there is a different API you can use https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html

Related

Call Fingerprint.scanFingerprint but fingerprint dialog doesn't show up when it is called again?

My app calls scanfingerprint and shows fingerprint dialog successfully. I scan my fingerprint and output "Scan successfully".
Fingerprint.scanFingerprint(ul.localStr("!fingerprint"), value -> {
System.out.pringln("Scan successfull!");
}, (sender, err, errorCode, errorMessage) -> {
System.out.pringln("Scan Failed!");
});
But when I call scanFinferpring again in the same process, it doesn't show a fingerprint dialog and outputs "Scan successful!" directly.
How to show the fingerpring dialog again if I want my user to log in again with fingerpring?
This isn't currently implemented but I filed an issue. It should be relatively trivial to add as it requires adding an additional native call to invalidate which would do nothing on most platforms but map to this on iOS.

Handle device features in codename one

for learning purposes, I am trying to write a simple sleep timer app. Purpose should be to have a picker, select a number of minutes and after that time, perform certain actions. Most importantly, activate flight mode and close all other applications to save the battery.
I have a custom picker and my runnable thread, which works fine:
#Override
public void run() {
while((System.currentTimeMillis() - startTime ) / 1000 < minutes){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("interrupted, go again.");
return;
}
}
System.out.println("Wait time is over, go to sleep.");
app.timeToSleep();
however, within "timeToSleep" I now want to do things like:
Device.setFlightmodeEnabled(true); or
TaskManager.killall();
How would I achieve something like that? I have not found anything so far, but maybe I have the wrong key words to look for.
Thanks and best regards
You can access some device features via API and some via native interfaces but I don't think setting a device to flightmode is technically possible without operator or Google authorization and that's only possible on Android...

CodenameOne IntentResultListener not being called

I have been trying to call an oAuth evernote library without success. The authentication works but my Codename One app is not notified via the startActivityForResult() mechanism. I have trimmed out as many factors as I can. I have currently reduced it to startActivityForResult() using the Contact application.
I now have a Codename One native class with the following code. (This is an example from https://developer.android.com/guide/components/intents-common.html).
private void selectContact() {
debugOut ("selectContact: Entry");
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener() {
public void onActivityResult (int requestCode, int resultCode, Intent data) {
debugOut ("onActivityResult: Entry");
}
});
debugOut ("selectContact: Exit");
}
A call to selectContact() launches the Contact application. When I pick a Contact, the Contact application closes. The system console shows both messages: "selectContact: Entry" and "selectContact: Exit".
The code in IntentResultListener.onActivityResult() is not called (ie ""onActivityResult: Entry" is not output).
I have tried to look at the Codename One source on GitHub (CodenameOneActivity.java), in particular this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//is this a payment result
if (mHelper != null && mHelper.handleActivityResult(requestCode, resultCode, data)) {
return;
}
IntentResult response = new IntentResult(requestCode, resultCode, data);
intentResult.add(response);
}
I'm likely looking in the wrong place but this does not appear to forward received Intents if it is not interested. (I am making an assumption that the cloud build uses CodenameOneActivity to build the Android app).
I think this effectively broke that functionality. I've filed an issue to track this.

Video having problems on my phone in Codename One

I have created an app for video demonstration using Codename one. I'm Facing some challenges when I'm running the app on my Google Android Phone as it does not allow a full screen view and also after the video is done playing, it does not go back or restart the video again. Another problem was that I had a button at the bottom at the borderlayout and each time I click the button, it corrupts the video and the video won't play anymore. These are codes used for my demonstration app Demonstration App 1, Demonstration App2 .
#Override
protected void postMain1(Form f) {
final MediaPlayer mp = findMpPresent();
try {
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/sbuda.mp4");
if (is != null) {
mp.setDataSource(is, "video/mp4", null);
} else {
}
} catch (IOException ex) {
ex.getMessage();
}
}
This is a bit unclear since I can't see the stop/start etc with a GUI builder application.
You can use native on-device controls for playback using setFullScreen. Notice that this works nicely on the device but has no equivalent on the simulator.
Once playback is finished the media no longer exists as your input stream has been depleted. You will need to create a new Media object. You can use the completion callback (the Runnable argument) to detect the end of the media.

Why does Codename One's NativeLookup.create return null?

I'm currently trying to get codename one working with some native code on windows phone. I created a "native demo" project where I changed the NativeCalls class to just support one simple method:
package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
public String testString();
}
from this one i used the context menu item "Generate Native" and changed the NativeCallsImpl.cs file to return "windows phone" when testString is called. The last change I made is within the StateMachine:
protected void onGUI1_AddNativeButtonAction(Component c, ActionEvent event) {
super.onGUI1_AddNativeButtonAction(c, event);
try {
NativeCalls n = (NativeCalls) NativeLookup.create(NativeCalls.class);
if (n != null) {
if (n.isSupported()) {
Dialog.show("Got string", n.testString(), "OK", null);
} else {
Dialog.show("Error", "Platform not supported!", "OK", null);
}
} else {
Dialog.show("Error", "Native lookup returned null!", "OK", null);
}
c.getComponentForm().revalidate();
} catch (Throwable t) {
Dialog.show("Error", "Exception during native access: " + t, "OK", null);
}
}
the build works perfectly fine and it also runs on the simulator. But when I'm deploying the xap file on my phone (via WP Dev Tools, QR code doesn't work, shows "company app couldn't been installed), the app boots normally but shows that the NativeLookup returned null. The built .jar file from within the dist-directory contains the .cs file in the correct location (com/codename1/nativedemo/NativeCallsImpl.cs, right besides NativeCalls.class)
A null is returned by this lookup is an exception is thrown or something failed during creation.
I'm not 100% sure this works properly in the current Windows Phone port.
FYI The current Windows Phone port is deprecated and undergoing a complete rewrite.

Resources