NaviRamyle
NaviRamyle

Reputation: 4007

How to overlay views in other apps

Where do I start?

I don't know what functions or permissions will I use to make this. No root required.

The view look like this, the camera button on the right side, it is floating and visible to other apps, if you push it, it will capture a screenshot.

enter image description here

Note: I will not make make a screenshot app, this is only an example of what I want to achieve.

Upvotes: 25

Views: 38954

Answers (2)

David LM
David LM

Reputation: 11

Try this:

    if(!isSystemAlertPermissionGranted(MainActivity.this)){
        requestSystemAlertPermission(MainActivity.this,1);
    }

    startService(new Intent(getApplicationContext(), Overlay.class));

And:

public static void requestSystemAlertPermission(Activity context, int requestCode) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return;
    final String packageName = context == null ? context.getPackageName() : context.getPackageName();
    final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));
    if (context != null)
        context.startActivityForResult(intent, requestCode);
    else
        context.startActivityForResult(intent, requestCode);
}
@TargetApi(23)
public static boolean isSystemAlertPermissionGranted(Context context) {
    final boolean result = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || Settings.canDrawOverlays(context);
    return result;
}

Upvotes: 1

Related Questions