From c071ef47071e397638df11e955c572ab6c6d28df Mon Sep 17 00:00:00 2001 From: haohao <358297604@qq.com> Date: Tue, 12 Jun 2018 15:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D8.0+=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E7=AA=97=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/gsyvideoplayer/WindowActivity.java | 4 ++-- .../gsyvideoplayer/utils/floatUtil/FloatPhone.java | 9 ++++++++- .../gsyvideoplayer/utils/floatUtil/Util.java | 13 ++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/example/gsyvideoplayer/WindowActivity.java b/app/src/main/java/com/example/gsyvideoplayer/WindowActivity.java index 5a4fafde2..5ecb1c467 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/WindowActivity.java +++ b/app/src/main/java/com/example/gsyvideoplayer/WindowActivity.java @@ -4,6 +4,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.provider.Settings; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; @@ -56,8 +57,7 @@ protected void onDestroy() { @RequiresApi(api = 23) private void requestAlertWindowPermission() { - Intent intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION"); - intent.setData(Uri.parse("package:" + getPackageName())); + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, 1); } diff --git a/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/FloatPhone.java b/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/FloatPhone.java index a3797ceba..7bb4d3776 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/FloatPhone.java +++ b/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/FloatPhone.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.PixelFormat; +import android.os.Build; import android.view.View; import android.view.WindowManager; @@ -33,9 +34,15 @@ public void setSize(int width, int height) { @Override public void setView(View view) { + int layout_type; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + layout_type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + } else { + layout_type = WindowManager.LayoutParams.TYPE_PHONE; + } mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - mLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; + mLayoutParams.type = layout_type; mLayoutParams.windowAnimations = 0; mView = view; } diff --git a/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/Util.java b/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/Util.java index 07c47a002..811e31172 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/Util.java +++ b/app/src/main/java/com/example/gsyvideoplayer/utils/floatUtil/Util.java @@ -2,7 +2,9 @@ import android.content.Context; import android.graphics.Point; +import android.os.Build; import android.provider.Settings; +import android.support.annotation.RequiresApi; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; @@ -22,16 +24,9 @@ static View inflate(Context applicationContext, int layoutId) { return inflate.inflate(layoutId, null); } + @RequiresApi(api = Build.VERSION_CODES.M) public static boolean hasPermission(Context context) { - Boolean result; - try { - Class clazz = Settings.class; - Method canDrawOverlays = clazz.getDeclaredMethod("canDrawOverlays", Context.class); - result = (Boolean) canDrawOverlays.invoke(null, context); - } catch (Exception e) { - result = false; - } - return result; + return Settings.canDrawOverlays(context); }