Skip to content

Commit

Permalink
Merge pull request CarGuo#1192 from haohaozaici/master
Browse files Browse the repository at this point in the history
修复8.0+悬浮窗权限
  • Loading branch information
CarGuo authored Jun 13, 2018
2 parents dad91e8 + c071ef4 commit f7a4153
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}


Expand Down

0 comments on commit f7a4153

Please sign in to comment.