Forms flick back and forward when calling native interface with "com.codename1.impl.android.AndroidNativeUtil.checkForPermission"

35 views
Skip to first unread message

mispro...@gmail.com

unread,
Jul 13, 2016, 6:36:05 AM7/13/16
to CodenameOne Discussions
Dear Sir,

When I call cn1 function "com.codename1.impl.android.AndroidNativeUtil.checkForPermission" for granting permission on android 6.0 in event "Post Show" from another page, the form will be flicked backward on allowing one permission.

For example

Form "First" there is button to form "Second"
@Override
protected void onFirst_ButtonAction(Component c, ActionEvent event) {

Form gui = showForm("Second", null);
gui.getMenuBar().removeAll();
}

In Second form
@Override
protected void postSecond(Form f) {
MobileNative mobileNative = (MobileNative) NativeLookup.create(MobileNative.class);
mobileNative.checkPermissions();

}

When I call the function to allow permissions, it flick from "Second" to "First" for each permission clicking allow
It is native function
public class MobileNativeImpl {

public boolean checkPermissions() {

if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "WRITE_EXTERNAL_STORAGE")){
// you didn't get the permission, you might want to return here
return false;
}
// you have the permission, do what you need

if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.SEND_SMS, "SEND_SMS")){
return false;
}

if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.WRITE_CONTACTS, "WRITE_CONTACTS")){
return false;
}

if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.READ_CONTACTS, "READ_CONTACTS")){
return false;
}

return true;
}

}

Please advice how to solve the problem, it may cause me not going to "Second" form in some circumstance.

Thanks and Regards,
Ronald

Chen Fishbein

unread,
Jul 13, 2016, 11:38:54 AM7/13/16
to CodenameOne Discussions, mispro...@gmail.com
Try to wrap these lines in callSerially:

Display.getInstance().callSerially(()->{

    Form gui = showForm("Second", null);
gui.getMenuBar().removeAll();

});

mispro...@gmail.com

unread,
Jul 13, 2016, 10:44:18 PM7/13/16
to CodenameOne Discussions, mispro...@gmail.com
I have tried but the flick issue still here. Would you have any solution? Thanks!

Shai Almog

unread,
Jul 14, 2016, 1:33:32 AM7/14/16
to CodenameOne Discussions, mispro...@gmail.com
Try checking one permission at a time and see if that helps.

mispro...@gmail.com

unread,
Jul 14, 2016, 1:41:13 AM7/14/16
to CodenameOne Discussions, mispro...@gmail.com
It is tried before. it flick once. Actually, the flick happen when i click allow

Shai Almog

unread,
Jul 15, 2016, 12:26:09 AM7/15/16
to CodenameOne Discussions, mispro...@gmail.com
What do you mean by "flick"? Do you mean it goes to the previous form?
Try doing this in the before  show.
Reply all
Reply to author
Forward
0 new messages