Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vivo X21A在应用回到后台时无法显示悬浮窗 #41

Open
pzl237 opened this issue Mar 14, 2019 · 3 comments
Open

vivo X21A在应用回到后台时无法显示悬浮窗 #41

pzl237 opened this issue Mar 14, 2019 · 3 comments

Comments

@pzl237
Copy link

pzl237 commented Mar 14, 2019

vivo X21A,应用在前台可以显示悬浮窗,当应用在后台,悬浮窗就消失了。需要进入到手机权限管理,手动打开应用的悬浮窗权限,应用在后台才能显示悬浮窗。有办法解决吗?

@zhaozepeng
Copy link
Owner

判断悬浮窗权限在vivo x21a上会失效么?

@pzl237
Copy link
Author

pzl237 commented Mar 18, 2019

会失效哦。目前找到了解决办法:
public class VIVOHelper {

public static boolean checkPermission(Context context) {
    return getFloatPermissionStatus(context) == 0;
}

public static void applyPermission(Fragment fragment, int requestCode) {
    Intent intent = applyIntent(fragment.getContext());
    if (intent != null) {
        fragment.startActivityForResult(intent, requestCode);
    }
}

/**
 * 获取悬浮窗权限状态
 *
 * @param context 上下文
 * @return 1或其他是没有打开,0是打开,该状态的定义和{@link android.app.AppOpsManager#MODE_ALLOWED},MODE_IGNORED等值差不多,自行查阅源码
 */
private static int getFloatPermissionStatus(Context context) {
    if (context == null) {
        throw new IllegalArgumentException("context is null");
    }
    String packageName = context.getPackageName();
    Uri uri = Uri.parse("content://com.iqoo.secure.provider.secureprovider/allowfloatwindowapp");
    String selection = "pkgname = ?";
    String[] selectionArgs = new String[]{packageName};
    Cursor cursor = context
            .getContentResolver()
            .query(uri, null, selection, selectionArgs, null);
    if (cursor != null) {
        cursor.getColumnNames();
        if (cursor.moveToFirst()) {
            int currentmode = cursor.getInt(cursor.getColumnIndex("currentlmode"));
            cursor.close();
            return currentmode;
        } else {
            cursor.close();
            return getFloatPermissionStatus2(context);
        }

    } else {
        return getFloatPermissionStatus2(context);
    }
}


/**
 * vivo比较新的系统获取方法
 *
 * @param context 上下文
 * @return 1或其他是没有打开,0是打开
 */
private static int getFloatPermissionStatus2(Context context) {
    String packageName = context.getPackageName();
    Uri uri2 = Uri.parse("content://com.vivo.permissionmanager.provider.permission/float_window_apps");
    String selection = "pkgname = ?";
    String[] selectionArgs = new String[]{packageName};
    Cursor cursor = context
            .getContentResolver()
            .query(uri2, null, selection, selectionArgs, null);
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            int currentmode = cursor.getInt(cursor.getColumnIndex("currentmode"));
            cursor.close();
            return currentmode;
        } else {
            cursor.close();
            return 1;
        }
    }
    return 1;
}

private static List<Intent> intentList(Context paramContext) {
    List<Intent> intents = new ArrayList<>();
    Intent localIntent = new Intent();
    localIntent.putExtra("packagename", paramContext.getPackageName());
    localIntent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.SoftPermissionDetailActivity"));
    intents.add(localIntent);

    localIntent = new Intent();
    localIntent.putExtra("packagename", paramContext.getPackageName());
    localIntent.setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.FloatWindowManager"));
    intents.add(localIntent);

    localIntent = new Intent();
    localIntent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.PurviewTabActivity"));
    intents.add(localIntent);

    localIntent = new Intent();
    localIntent.setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.MainActivity"));
    intents.add(localIntent);

    localIntent = new Intent();
    localIntent.setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.MainGuideActivity"));
    intents.add(localIntent);
    return intents;
}

@SuppressLint("WrongConstant")
private static boolean canQueryIntent(Context paramContext, Intent paramIntent) {
    boolean bool;
    if (paramContext.getPackageManager().queryIntentActivities(paramIntent, PackageManager.GET_PERMISSIONS).size() > 0)
        bool = true;
    else
        bool = false;
    return bool;
}

private static Intent applyIntent(Context paramContext) {
    List<Intent> intentList = intentList(paramContext);
    Intent destIntent = null;
    if (intentList.isEmpty()) {
        return null;
    }
    for (Intent intent : intentList) {
        if (canQueryIntent(paramContext, intent)) {
            destIntent = intent;
            break;
        }
    }
    return destIntent;
}

}

@zhaozepeng
Copy link
Owner

可以麻烦发一个Pull request么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants