關於MIUI懸浮窗許可權問題的解決方案,miui懸浮解決方案

來源:互聯網
上載者:User

關於MIUI懸浮窗許可權問題的解決方案,miui懸浮解決方案

先扯會....好久沒寫Blog了....這段時間有點小忙...瞎忙.....忙的自己都感覺都不應該.....嚴重影響了生活品質......生活的幸福指數!!!.....到現在還特麼的單身!!!求介紹啊......

MIUI是我個人非常喜歡的ROM....雖然有諸多的不爽....但是搞開發就能理解.....寫好一個產品是多麼的不易.....好多東西的不可控....精力的有限! 現在買手機都看能不能刷MIUI..不能刷的就猶豫了.....

===============盜鏈....盜內容的都是Erbility, Shability  ========================

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

步入正題.....解決這個問題...無非就是2點

1.跳轉

2.判斷是否真的開啟

......代碼開啟是別想了....要不然人家也不能弄著玩啊.....除非是你發現了什麼....

跳轉的思路很簡單..手動找到那個介面..看看是哪個Activity.

   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;    }

再通過ComponentName想知道什麼不行啊.....不知道怎麼執行....能想到這個問題...不應該吧....隨便建議一下....跑個線程

下面就是跳轉了....

  /**     * 開啟MIUI許可權管理介面(MIUI v5, v6)     * @param context     */    public static void openMiuiPermissionActivity(Context context) {        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.AppPermissionsEditorActivity");            intent.putExtra("extra_pkgname", context.getPackageName());        }                if (isIntentAvailable(context, intent)) {            if (context instanceof Activity) {                Activity a = (Activity) context;                a.startActivityForResult(intent, 2);            }        } else {            Flog.e("Intent is not available!");        }    }

很可惜....V5的懸浮窗許可權在應用詳情裡面...

  @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!");        }    }

另外加了個Intent的判斷

  /**     * 判斷是否有可以接受的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, v6不知道怎麼判斷? 好吧...有點跑題了....

    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";    }    

根據返回的是V5還是V6判斷

=====完成跳轉.....下面就是判斷了......自己是沒琢磨出來....問的MIUI的工程師.....小帥哥太帥了.....感謝.....

    /**     * 判斷MIUI的懸浮窗許可權     * @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);  //自己寫就是24 為什麼是24?看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; }

到這兒就完事了...沒想到牽扯的代碼還挺多.......


MIUI開發版懸浮窗問題

嗨!
你好,請在設定--全部設定--應用--找到該軟體開啟懸浮框即可。更多MIUI技巧和優惠活動可以關注MIUI官方微博weibo.com/miui官方MIUI米柚

小米企業平台[官方認證]

懸浮視窗按鈕開啟了,但顯示不了懸浮視窗,什原因?怎解決?(miui v5 開發版3412)解決

您好!
有些軟體自身就是不支援懸浮窗顯示的。
感謝您的支援,祝您生活愉快!
歡迎您在百度小米企業平台提問:zhidao.baidu.com/c/xiaomi/
小米企業平台[官方認證]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.