Android 如何在其他应用中叠加视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20461979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to overlay views in other apps
提问by NaviRamyle
Where do I start?
我从哪里开始?
I don't know what functions or permissions will I use to make this. No root required.
我不知道我将使用什么功能或权限来实现这一点。无需root。
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.
注意:我不会制作截图应用程序,这只是我想要实现的一个例子。
采纳答案by Mohammad Ersan
this called
这叫
Draw Over Other Apps
绘制其他应用程序
check these answers
检查这些答案
"DRAW OVER OTHER APP" is which permission in android
“DRAW OVER OTHER APP”是android中的哪个权限
How to draw a view on top of everything?
(from Morrison Chang) What APIs in Android is Facebook using to create Chat Heads?
(来自 Morrison Chang) Facebook 使用 Android 中的哪些 API 来创建聊天头?
回答by David LM
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;
}