[Free/OS] OverlayPermission Extension

package com.carrom.overlaypermission;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;

@DesignerComponent(
        version = 1,
        description = "Requests and checks overlay permission for displaying over other apps.",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "aiwebres/icon.png")

@SimpleObject(external = true)
public class OverlayPermission extends AndroidNonvisibleComponent {

    private final Context context;
    private final Activity activity;

    public OverlayPermission(ComponentContainer container) {
        super(container.$form());
        this.context = container.$context();
        this.activity = container.$context();
    }

    @SimpleFunction(description = "Checks if the overlay permission is granted.")
    public boolean IsPermissionGranted() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return true;
        }
        return Settings.canDrawOverlays(context);
    }

    @SimpleFunction(description = "Opens the system settings to request overlay permission.")
    public void RequestPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(context)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + context.getPackageName()));
            activity.startActivity(intent);
        }
    }
}

Hie @alrhmyly662

Welcome to Kodular community

Can you please elaborate more, with this code. What is this about? Are you sharing the code? Do you need help with the code? Do want someone to compile this code?

Please explain yourself

Compiled extension using FAST-CLI:
com.carrom.overlaypermission.aix (5.0 KB)

Source Project:
overlay-permission.zip (10.9 KB)

1 Like

Hi @JEWEL i tested the aix, it works, but i thinks something is missing, after calling it, it successfully open the Display over other apps, but the app isnโ€™t listed there,