About the MIUI floating window permission solution, miui floating Solution

Source: Internet
Author: User

About the MIUI floating window permission solution, miui floating Solution

Let's get started .... I haven't written a Blog for a long time .... this time is a little busy... busy ..... I don't feel like I'm busy ..... seriously affecting the quality of life ...... happiness Index of life !!!..... It's still a singleton !!! Please introduce ......

MIUI is my favorite ROM .... although there are a lot of unhappiness .... but developers can understand it ..... how difficult it is to write a product ..... A lot of things are uncontrollable .... limited effort! Now I can see if I can brush MIUI. If I can't, I will hesitate .....

=================== Leeching .... all content stolen is Erbility, Shability ======================

===================== Http://www.cnblogs.com/fangyucun/p/4027750.html=================

Step into the question... solve this problem... nothing more than 2 points

1. Jump

2. Determine whether to enable it.

... Don't think about opening the code... or someone else can't play with it... unless you find something ....

The jump idea is very simple. Manually find the interface... to see which Activity it is.

   public static ComponentName getTopComponentName(Context context) {        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);        List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);        ComponentName componentName = taskInfo.get(0).topActivity;        return componentName;    }

I want to know what I can do through ComponentName ..... I don't know how to execute .... think of this question... shouldn't you .... try again .... running threads

The following is the jump ....

/*** Open the MIUI permission management interface (MIUI v5, v6) * @ param context */public static void openMiuiPermissionActivity (Context context) {Intent intent Intent = new Intent ("miui. intent. action. APP_PERM_EDITOR "); String rom = RomUtils. getRom (); if (RomUtils. ROM_MIUI_V5.equals (rom) {PackageInfo pInfo = null; try {pInfo = context. getPackageManager (). getPackageInfo (packageName, 0);} catch (NameNotFoundException e) {Flog. e (e );} Intent. setClassName (SETTINGS_PACKAGE_NAME, "com. miui. securitycenter. permission. appPermissionsEditor "); intent. putExtra ("extra_package_uid", pInfo. applicationInfo. uid);} else if (RomUtils. ROM_MIUI_V6.equals (rom) {intent. setClassName ("com. miui. securitycenter "," com. miui. permcenter. permissions. apppermissionseditequaltient "); intent. putExtra ("extra_pkgname", context. getPackageName ();} if (isIn TentAvailable (context, intent) {if (context instanceof Activity) {Activity a = (Activity) context;. startActivityForResult (intent, 2) ;}} else {Flog. e ("Intent is not available! ");}}

Unfortunately... V5's floating window permission is in the application details...

  @TargetApi(9)    public static void openAppDetailActivity(Context context, String packageName) {        Intent intent = null;        if (Build.VERSION.SDK_INT >= 9) {            intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);            Uri uri = Uri.fromParts(SCHEME_PACKAGE, packageName, null);            intent.setData(uri);        } else {            final String className = Build.VERSION.SDK_INT == 8 ?                     SETTINGS_APPDETAILS_CLASS_NAME_22 : SETTINGS_APPDETAILS_CLASS_NAME_B21;            intent = new Intent(Intent.ACTION_VIEW);            intent.setClassName(SETTINGS_PACKAGE_NAME, SETTINGS_APPDETAILS_CLASS_NAME);            intent.putExtra(className, packageName);        }        if (isIntentAvailable(context, intent)) {            context.startActivity(intent);        } else {            Flog.e("intent is not available!");        }    }

In addition, Intent judgment is added.

/*** Determine whether there is an acceptable Activity * @ param context * @ param action * @ return */public static boolean isIntentAvailable (Context context, Intent intent) {if (intent = null) return false; return context. getPackageManager (). queryIntentActivities (intent, PackageManager. GET_ACTIVITIES ). size ()> 0 ;}

V5 and v6 do not know how to judge? Okay... a bit out of question ....

    public static String getSystemProperty() {        String line = null;        BufferedReader reader = null;        try {            Process p = Runtime.getRuntime().exec("getprop ro.miui.ui.version.name" );            reader = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);            line = reader.readLine();            return line;        } catch (IOException e) {            Flog.e(e);        } finally {            IoUtils.close(reader);        }        return "UNKNOWN";    }    

Determine whether to return V5 or V6

===== Complete the jump ..... the following is the judgment ...... I did not figure it out .... ask MIUI engineers ..... handsome guy ..... thank you .....

/*** Determine the permission of the MIUI floating window * @ param context * @ return */@ TargetApi (Build. VERSION_CODES.KITKAT) public static boolean isMiuiFloatWindowOpAllowed (Context context) {final int version = Build. VERSION. SDK_INT; if (version> = 19) {checkOp (context, OP_SYSTEM_ALERT_WINDOW); // Why is 24 written by myself? View AppOpsManager} else {if (context. getApplicationInfo (). flags & 1 <27) = 1) {return true;} else {return false ;}} return false ;}
@ TargetApi (Build. VERSION_CODES.KITKAT) public static boolean checkOp (Context context, int op) {final int version = Build. VERSION. SDK_INT; if (version> = 19) {AppOpsManager manager = (AppOpsManager) context. getSystemService (Context. APP_OPS_SERVICE); try {if (AppOpsManager. MODE_ALLOWED = (Integer) ReflectUtils. invokeMethod (manager, "checkOp", op,
Binder. getCallingUid (), context. packageName () {// return true;} else {return false;} catch (Exception e) {Flog. e (e. getMessage () ;}} else {Flog. e ("Below API 19 cannot invoke! ");} Return false ;}

It's all done here... I didn't expect a lot of code involved .......


Floating window of MIUI development Edition

Hi!
Hi, please go to settings -- all settings -- Application -- find the software and open the floating box. For more MIUI tips and promotions, visit the MIUI official Weibo weibo.com/miuiofficial miuimiyou.

Xiaomi enterprise Platform [Official Certification]

The floating window button is opened, but the floating window cannot be displayed. Why? How can this problem be solved? (Miui v5 development version 3412) Solution

Hello!
Some software itself does not support floating window display.
Thank you for your support and wish you a happy life!
You are welcome to ask a question on Baidu Xiaomi enterprise platform: zhidao.baidu.com/c/xiaomi/
Xiaomi enterprise Platform [Official Certification]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.