├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ ├── float_window_layout.xml
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── android
│ │ └── floatwindowpermission
│ │ ├── FloatWindowActivity.java
│ │ ├── FloatWindowManager.java
│ │ └── FloatView.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── linchaolong
│ │ │ └── android
│ │ │ └── floatingpermissioncompat
│ │ │ ├── impl
│ │ │ ├── BelowApi23CompatImpl.java
│ │ │ ├── MeizuCompatImpl.java
│ │ │ ├── QihooCompatImpl.java
│ │ │ ├── Api23CompatImpl.java
│ │ │ ├── HuaweiCompatImpl.java
│ │ │ └── MiuiCompatImpl.java
│ │ │ ├── Utils.java
│ │ │ └── FloatingPermissionCompat.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── linchaolong
│ │ │ └── android
│ │ │ └── floatingpermissioncompat
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── linchaolong
│ │ └── android
│ │ └── floatingpermissioncompat
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── bintrayUpload.bat
├── screenshot.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/bintrayUpload.bat:
--------------------------------------------------------------------------------
1 | gradlew build bintrayUpload & pause
2 |
3 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/screenshot.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CYRUS-STUDIO/FloatingPermissionCompat/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 | 悬浮窗适配
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 12 23:08:42 GMT+08:00 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/test/java/com/linchaolong/android/floatingpermissioncompat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test public void addition_isCorrect() throws Exception {
14 | assertEquals(4, 2 + 2);
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/float_window_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | # External native build folder generated in Android Studio 2.2 and later
43 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\zhaozp\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
--------------------------------------------------------------------------------
/library/src/main/java/com/linchaolong/android/floatingpermissioncompat/impl/BelowApi23CompatImpl.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat.impl;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import com.linchaolong.android.floatingpermissioncompat.FloatingPermissionCompat;
6 |
7 | /**
8 | * Android 6.0 以下的通用实现基类
9 | *
10 | * Created by linchaolong on 2016/12/26.
11 | */
12 | public abstract class BelowApi23CompatImpl implements FloatingPermissionCompat.CompatImpl {
13 |
14 | @Override public boolean check(Context context) {
15 | final int version = Build.VERSION.SDK_INT;
16 | if (version >= 19) {
17 | return FloatingPermissionCompat.checkOp(context, 24); // 悬浮窗权限的 op 值是 OP_SYSTEM_ALERT_WINDOW = 24;
18 | }
19 | return true;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/library/src/main/java/com/linchaolong/android/floatingpermissioncompat/impl/MeizuCompatImpl.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat.impl;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | /**
7 | * 魅族悬浮窗权限兼容实现
8 | *
9 | * Created by linchaolong on 2016/12/26.
10 | */
11 | public class MeizuCompatImpl extends BelowApi23CompatImpl {
12 |
13 | @Override public boolean isSupported() {
14 | return true;
15 | }
16 |
17 | /**
18 | * 去魅族权限申请页面
19 | */
20 | @Override public boolean apply(Context context) {
21 | Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
22 | intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");
23 | intent.putExtra("packageName", context.getPackageName());
24 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
25 | context.startActivity(intent);
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
6 |
7 |
8 |
9 |
15 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/linchaolong/android/floatingpermissioncompat/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
18 | @Test public void useAppContext() throws Exception {
19 | // Context of the app under test.
20 | Context appContext = InstrumentationRegistry.getTargetContext();
21 |
22 | assertEquals("com.linchaolong.android.floatingpermissioncompat.test", appContext.getPackageName());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Developer\Android\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
3 | */
4 | apply plugin: 'com.android.application'
5 |
6 | android {
7 | compileSdkVersion 25
8 | buildToolsVersion '25.0.2'
9 | defaultConfig {
10 | applicationId "com.android.floatwindowpermission"
11 | minSdkVersion 13
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | testCompile 'junit:junit:4.12'
31 | compile 'com.android.support:appcompat-v7:25.3.1'
32 | // compile 'com.linchaolong.android:floatingpermissioncompat:1.0'
33 | compile project(':library')
34 | }
35 |
--------------------------------------------------------------------------------
/library/src/main/java/com/linchaolong/android/floatingpermissioncompat/impl/QihooCompatImpl.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat.impl;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.util.Log;
6 | import com.linchaolong.android.floatingpermissioncompat.Utils;
7 |
8 | /**
9 | * 360 悬浮窗权限兼容实现
10 | *
11 | * Created by linchaolong on 2016/12/26.
12 | */
13 | public class QihooCompatImpl extends BelowApi23CompatImpl {
14 |
15 | private static final String TAG = "QihooCompatImpl";
16 |
17 | @Override public boolean isSupported() {
18 | return true;
19 | }
20 |
21 | @Override public boolean apply(Context context) {
22 | Intent intent = new Intent();
23 | intent.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
24 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
25 | if (Utils.isIntentAvailable(context, intent)) {
26 | context.startActivity(intent);
27 | return true;
28 | } else {
29 | intent.setClassName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.appEnterActivity");
30 | if (Utils.isIntentAvailable(context, intent)) {
31 | context.startActivity(intent);
32 | return true;
33 | } else {
34 | Log.e(TAG, "can't open permission page with particular name, please use " +
35 | "\"adb shell dumpsys activity\" command and tell me the name of the float window permission page");
36 | }
37 | }
38 | return false;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/floatwindowpermission/FloatWindowActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
3 | */
4 | package com.android.floatwindowpermission;
5 |
6 | import android.app.Activity;
7 | import android.content.DialogInterface;
8 | import android.os.Bundle;
9 | import android.support.v7.app.AlertDialog;
10 | import android.view.View;
11 | import com.linchaolong.android.floatingpermissioncompat.FloatingPermissionCompat;
12 |
13 | /**
14 | * Description:
15 | *
16 | * @author zhaozp
17 | * @since 2016-10-17
18 | */
19 |
20 | public class FloatWindowActivity extends Activity {
21 |
22 | Activity context;
23 |
24 | @Override protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | context = this;
28 | findViewById(R.id.btn_show_or_apply).setOnClickListener(new View.OnClickListener() {
29 | @Override public void onClick(View v) {
30 | // 检查是否已经授权
31 | if (FloatingPermissionCompat.get().check(context)) {
32 | FloatWindowManager.get().show(context);
33 | } else {
34 | // 授权提示
35 | new AlertDialog.Builder(context).setTitle("悬浮窗权限未开启")
36 | .setMessage("你的手机没有授权" + context.getString(R.string.app_name) + "获得悬浮窗权限,视频悬浮窗功能将无法正常使用")
37 | .setPositiveButton("开启", new DialogInterface.OnClickListener() {
38 | @Override public void onClick(DialogInterface dialog, int which) {
39 | // 显示授权界面
40 | FloatingPermissionCompat.get().apply(context);
41 | }
42 | })
43 | .setNegativeButton("取消", null).show();
44 | }
45 | }
46 | });
47 |
48 | findViewById(R.id.btn_dismiss).setOnClickListener(new View.OnClickListener() {
49 | @Override public void onClick(View v) {
50 | FloatWindowManager.get().dismiss();
51 | }
52 | });
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/main/java/com/linchaolong/android/floatingpermissioncompat/impl/Api23CompatImpl.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat.impl;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.provider.Settings;
8 | import android.util.Log;
9 | import com.linchaolong.android.floatingpermissioncompat.FloatingPermissionCompat;
10 | import java.lang.reflect.Field;
11 | import java.lang.reflect.Method;
12 |
13 | /**
14 | * Android 6.0 以上悬浮窗权限申请实现
15 | *
16 | * Created by linchaolong on 2016/12/26.
17 | */
18 | public class Api23CompatImpl implements FloatingPermissionCompat.CompatImpl{
19 |
20 | private static final String TAG = "Api23CompatImpl";
21 |
22 | @Override public boolean check(Context context) {
23 | boolean result = true;
24 | if (Build.VERSION.SDK_INT >= 23) {
25 | try {
26 | Class clazz = Settings.class;
27 | Method canDrawOverlays = clazz.getDeclaredMethod("canDrawOverlays", Context.class);
28 | result = (Boolean) canDrawOverlays.invoke(null, context);
29 | } catch (Exception e) {
30 | Log.e(TAG, Log.getStackTraceString(e));
31 | }
32 | }
33 | return result;
34 | }
35 |
36 | @Override public boolean isSupported() {
37 | return true;
38 | }
39 |
40 | /**
41 | * 通用 rom 权限申请
42 | *
43 | * @param context
44 | * @return
45 | */
46 | @Override public boolean apply(Context context) {
47 | try {
48 | Class clazz = Settings.class;
49 | Field field = clazz.getDeclaredField("ACTION_MANAGE_OVERLAY_PERMISSION");
50 | Intent intent = new Intent(field.get(null).toString());
51 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
52 | intent.setData(Uri.parse("package:" + context.getPackageName()));
53 | context.startActivity(intent);
54 | return true;
55 | } catch (Exception e) {
56 | Log.e(TAG, Log.getStackTraceString(e));
57 | }
58 | return false;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 13
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | publish {
25 | // 读取 local.properties 中配置
26 | Properties properties = new Properties()
27 | File localPropertiesFile = rootProject.file("local.properties");
28 | if (localPropertiesFile.exists()) {
29 | properties.load(localPropertiesFile.newDataInputStream())
30 | }
31 | // 用户名
32 | bintrayUser = properties.getProperty("bintrayUser")
33 | if(bintrayUser == null && project.hasProperty("bintrayUser")){
34 | bintrayUser = project.property("bintrayUser")
35 | }
36 | // apkKey
37 | bintrayKey = properties.getProperty("bintrayKey")
38 | if(bintrayKey == null && project.hasProperty("bintrayKey")){
39 | bintrayKey = project.property("bintrayKey")
40 | }
41 | // 仓库名称,默认maven
42 | repoName = 'maven'
43 | // 组织名称
44 | userOrg = 'linchaolong'
45 | //compile 'groupId:artifactId:publishVersion'
46 | groupId = 'com.linchaolong.android'
47 | artifactId = 'floatingpermissioncompat'
48 | publishVersion = '1.0'
49 | // 项目描述
50 | desc = 'Android下的悬浮窗权限兼容库(android floating permission compatibility library)'
51 | // 项目地址
52 | website = 'https://github.com/linchaolong/FloatingPermissionCompat'
53 | // 如果设置为true,它将运行所有内容,但不会将包上传到bintray。如果是false,那么它会正常上传。
54 | dryRun = false
55 | }
56 |
57 | dependencies {
58 | compile fileTree(dir: 'libs', include: ['*.jar'])
59 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
60 | exclude group: 'com.android.support', module: 'support-annotations'
61 | })
62 | testCompile 'junit:junit:4.12'
63 | }
64 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/src/main/java/com/linchaolong/android/floatingpermissioncompat/impl/HuaweiCompatImpl.java:
--------------------------------------------------------------------------------
1 | package com.linchaolong.android.floatingpermissioncompat.impl;
2 |
3 | import android.content.ActivityNotFoundException;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.util.Log;
8 | import com.linchaolong.android.floatingpermissioncompat.Utils;
9 |
10 | /**
11 | * 华为悬浮窗权限兼容实现
12 | *
13 | * Created by linchaolong on 2016/12/26.
14 | */
15 | public class HuaweiCompatImpl extends BelowApi23CompatImpl {
16 |
17 | private static final String TAG = "HuaweiCompatImpl";
18 |
19 | @Override public boolean isSupported() {
20 | return true;
21 | }
22 |
23 | @Override public boolean apply(Context context) {
24 | try {
25 | Intent intent = new Intent();
26 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
27 | // ComponentName comp = new ComponentName("com.huawei.systemmanager","com.huawei.permissionmanager.ui.MainActivity");//华为权限管理
28 | // ComponentName comp = new ComponentName("com.huawei.systemmanager",
29 | // "com.huawei.permissionmanager.ui.SingleAppActivity");//华为权限管理,跳转到指定app的权限管理位置需要华为接口权限,未解决
30 | ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.addviewmonitor.AddViewMonitorActivity");//悬浮窗管理页面
31 | intent.setComponent(comp);
32 | if (Utils.getEmuiVersion() == 3.1) {
33 | //emui 3.1 的适配
34 | context.startActivity(intent);
35 | } else {
36 | //emui 3.0 的适配
37 | comp = new ComponentName("com.huawei.systemmanager", "com.huawei.notificationmanager.ui.NotificationManagmentActivity");//悬浮窗管理页面
38 | intent.setComponent(comp);
39 | context.startActivity(intent);
40 | }
41 | } catch (SecurityException e) {
42 | Intent intent = new Intent();
43 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
44 | // ComponentName comp = new ComponentName("com.huawei.systemmanager","com.huawei.permissionmanager.ui.MainActivity");//华为权限管理
45 | ComponentName comp = new ComponentName("com.huawei.systemmanager",
46 | "com.huawei.permissionmanager.ui.MainActivity");//华为权限管理,跳转到本app的权限管理页面,这个需要华为接口权限,未解决
47 | //ComponentName comp = new ComponentName("com.huawei.systemmanager","com.huawei.systemmanager.addviewmonitor.AddViewMonitorActivity");//悬浮窗管理页面
48 | intent.setComponent(comp);
49 | context.startActivity(intent);
50 | Log.e(TAG, Log.getStackTraceString(e));
51 | } catch (ActivityNotFoundException e) {
52 | /**
53 | * 手机管家版本较低 HUAWEI SC-UL10
54 | */
55 | Intent intent = new Intent();
56 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
57 | ComponentName comp = new ComponentName("com.Android.settings", "com.android.settings.permission.TabItem");//权限管理页面 android4.4
58 | //ComponentName comp = new ComponentName("com.android.settings","com.android.settings.permission.single_app_activity");//此处可跳转到指定app对应的权限管理页面,但是需要相关权限,未解决
59 | intent.setComponent(comp);
60 | context.startActivity(intent);
61 | Log.e(TAG, Log.getStackTraceString(e));
62 | } catch (Exception e) {
63 | //抛出异常时提示信息
64 | Log.e(TAG, Log.getStackTraceString(e));
65 | }
66 | return false;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FloatingPermissionCompat
2 |
3 | this repository is aimed to adapt android float window permission in most of phone models and how to request it at runtime
4 |
5 | its result is as follows :
6 | 
7 |
8 | if you want to see more,[click here](http://blog.csdn.net/self_study/article/details/52859790)
9 |
10 | from now on,the models below android M that have been adapted are :
11 |
xiaomi:v5,v6,v7,v8
huawei:partial
meizu:partial
360:partial
others:phones like samsung,sony or other model can directly show the float window, so there is no need to adapt,but if you find one that can not,contact me via my email(zhao_zepeng@hotmail.com) or leave a message on my blog i mentioned above,thanks