Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlay views in other apps

Tags:

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.

like image 721
NaviRamyle Avatar asked Dec 09 '13 02:12

NaviRamyle


People also ask

How do you overlay views on Android?

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.

What does allow display over other apps mean?

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.

What is an overlay in an app?

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.


2 Answers

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?

like image 135
Mohammad Ersan Avatar answered Oct 15 '22 11:10

Mohammad Ersan


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; } 
like image 30
David LM Avatar answered Oct 15 '22 09:10

David LM