Android系统的覆盖窗口 [英] Android System overlay window

查看:4358
本文介绍了Android系统的覆盖窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个系统的覆盖。不过,我不断收到权限被拒绝。我使用的SDK版本23。

我的清单文件:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.test>

<使用-权限的Andr​​oid:名称=android.permission.SYSTEM_OVERLAY_WINDOW/>

<应用
    机器人:allowBackup =真
    机器人:图标=@纹理映射/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名称=。activity.MainActivity
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>

< /舱单>
 

在code我用它来创建覆盖:

  // MVIEW =新HUDView(本);
    mButton =新的按钮(这一点);
    mButton.setText(覆盖按钮);
    mButton.setOnTouchListener(本);

    WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.RIGHT | Gravity.TOP;
    params.setTitle(平均负载);
    窗口管理WM =(窗口管理器)getSystemService(WINDOW_SERVICE);
    wm.addView(mButton,则params);
 

解决方案

首先,没有命名的权限 SYSTEM_OVERLAY_WINDOW 。这是 SYSTEM_ALERT_WINDOW

二,如果你的 targetSdkVersion 是23或更高,而你在Android 6.0+设备上运行,你的应用程序不会得到该许可在一开始就。呼叫 Settings.canDrawOverlays()来看看,如果你有权限,并使用 ACTION_MANAGE_OVERLAY_PERMISSION 引领用户在设置如果你不知道。

I'm trying to create a system overlay. But I keep getting "permission denied". I'm using SDK version 23.

My manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test" >

<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".activity.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

The code I use to create the overlay:

    //mView = new HUDView(this);
    mButton = new Button(this);
    mButton.setText("Overlay button");
    mButton.setOnTouchListener(this);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.RIGHT | Gravity.TOP;
    params.setTitle("Load Average");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(mButton, params);

解决方案

First, there is no permission named SYSTEM_OVERLAY_WINDOW. It is SYSTEM_ALERT_WINDOW.

Second, if your targetSdkVersion is 23 or higher, and you are running on Android 6.0+ devices, your app will not get this permission at the outset. Call Settings.canDrawOverlays() to see if you have the permission, and use ACTION_MANAGE_OVERLAY_PERMISSION to lead the user over to Settings if you do not.

这篇关于Android系统的覆盖窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆