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.
Note: I will not make make a screenshot app, this is only an example of what I want to achieve.
Simply use RelativeLayout or FrameLayout . The last child view will overlay everything else. Android supports a pattern which Cocoa Touch SDK doesn't: Layout management.
Using an Android feature called "Draw over other apps," in which an image or dialog box appears on top of anything else that might be on your device's screen. The "chat heads" used by Facebook Messenger are one example of how this works. Google routinely grants apps the right to draw over other apps if they request it.
A screen overlay in Android, also referred to as “Draw On Top”, allows an app to display content over another app. The Android app permission SYSTEM_ALERT_WINDOW makes this possible. If you've ever used an app like Facebook Messenger or Lastpass, you've experienced screen overlay in action.
this called
Draw Over Other Apps
check these answers
"DRAW OVER OTHER APP" is which permission in android
How to draw a view on top of everything?
(from Morrison Chang) What APIs in Android is Facebook using to create Chat Heads?
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With