TaifunFlashlight extension and Camera.ToggleLight component both works fine with companion but doesn't work after installing apk

Hi,
I almost finished finished making flashlight app, but when i installed apk to phone it doesn’t work.

with TaifunFlashlight extension >> All images and texts are changed but flashlight doesn’t turned on.

with camera.togglelight component >> Following Runtime Error Notification Apears.

But both component works fine in companion.

app will work if it app ask for camera permission, if no then go to your application details page and manually enable the camera permission and try again. If this method doesn’t work then try to restart your phone.

thank you for reply @techcvr
Please can u tell me how to ask for camera permission?

I tried restarting phone but problem not solved.

it will automatically ask when your app request camera component.

Wrong.
@Taifun must update his extension that it use the new app inventor permission system.

Btw @saraswoti_stha88
You dont need to use the extension…
Just use our build in component.

All of our components do this automatic for you…

Just the extension developers (ALL extension developers) must update her extensions If they use “dangerous permissions”.

i didn’t said that anything about the extension from taifun. In @saraswoti_stha88 block screenshot image, camera component is used not extension.

@saraswoti_stha88
The developer docs say this:
“throws an exception if the camera is already in use by another application”.

So my question… how much times did you tried to use the blocks?
Have you had opened the camera before with another application?

Issue solved after adding following block >>>>

Thank you everyone for your kind support!

I catched the issue.
The needed permission was only asked automatic on the take picture block.
I will add the permission ask code to the toggle light block now too for next release.

3 Likes

Are we able to do this without having access to form?

Yes you should.
Because ai uses too the form.

And this means you have access.

Ok now I tried adding permission to mine, can you maybe give an example since your more pro at this :sweat_smile: or PM me to help? Idk.

private boolean havePermission = false;

    if (!havePermission) {
        form.askPermission(Manifest.permission.CAMERA,
                new PermissionResultHandler() {
                    @Override
                    public void HandlePermissionResponse(String permission, boolean granted) {
                        if (granted) {
                            Camera.this.havePermission = true;
                            ToggleLight();
                        } else {
                            form.dispatchPermissionDeniedEvent(Camera.this, "ToggleLight",
                                    Manifest.permission.CAMERA);
                        }
                    }
                });
        return;
    }
    //add here now the code which needs the above permission

You should use the code above in “void” like:

public void runMyMethod() {
    if (!havePermission) {
        form.askPermission(Manifest.permission.CAMERA,
                new PermissionResultHandler() {
                    @Override
                    public void HandlePermissionResponse(String permission, boolean granted) {
                        if (granted) {
                            Camera.this.havePermission = true;
                            ToggleLight();
                        } else {
                            form.dispatchPermissionDeniedEvent(Camera.this, "ToggleLight",
                                    Manifest.permission.CAMERA);
                        }
                    }
                });
        return;
    }
    //add here now the code which needs the above permission
}
1 Like

Thats why I kept getting the error, I though I had to do a private @SimpleFunction. Silly me :man_facepalming:

If you want a visible block then it must be public.

If you only create a helper method for your extension it can be private without the @SimpleFunction
like

private void myNiceHelper(int a, int b) {
    if (a > b) {
        //...
    }
}
1 Like

Where

are you getting this and this from…

It was just a example from the camera component.

1 Like

I used an example from form :thinking: I’ll take a look at it, I just updated the source.

the flashlight extension now is updated and uses the new SDK 26 features
Taifun

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.