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

display pop-up window in foreground and in background #412

Closed
bmp123 opened this issue Feb 18, 2020 · 15 comments
Closed

display pop-up window in foreground and in background #412

bmp123 opened this issue Feb 18, 2020 · 15 comments

Comments

@bmp123
Copy link

bmp123 commented Feb 18, 2020

Question

is it possible to request xiaomi permissions to display pop-up window in foreground and in background?

@zoontek zoontek closed this as completed Feb 18, 2020
@zoontek
Copy link
Owner

zoontek commented Feb 18, 2020

@bmp123 Only in foreground, using Android Permissions API.

@bmp123
Copy link
Author

bmp123 commented Feb 20, 2020

@zoontek I don't found anything about this permissions in android documentation, maybe you can give link?
image

@zoontek
Copy link
Owner

zoontek commented Feb 20, 2020

Sorry I didn't understand correctly your question at first. A bit more context (and the screenshot) helped.

We support Android permissions from the manifest: https://developer.android.com/reference/android/Manifest.permission. If it's not specific to MIUI (Xiaomi OS), it should be in it.

@bmp123
Copy link
Author

bmp123 commented Feb 20, 2020

But if it's specific to MIUI how can I get this permissions programmatically? Maybe you know

@bmp123
Copy link
Author

bmp123 commented Feb 20, 2020

Or these permissions get's only from settings?

@zoontek
Copy link
Owner

zoontek commented Feb 20, 2020

I search for it on internet without any success. I only found https://stackoverflow.com/questions/59645936/displaying-popup-windows-while-running-in-the-background, but there is not code to request the permission directly 😞

@bmp123
Copy link
Author

bmp123 commented Feb 21, 2020

thank you so much for your answers

@dev-Shivam96
Copy link

you can directly open other permission screen for MIUI (Xiaomi OS) devices using following code:

Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR"); intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity"); intent.putExtra("extra_pkgname", getPackageName()); startActivity(intent);

but, now problem is how we can check is permission is granted or not ?
If anyone know, please tell me how can check permission.

@prvnmit
Copy link

prvnmit commented Jul 30, 2020

I see that the background pop up window permission is granted by default for apps like Amazon Music and Airbnb. How come that's possible for them?

@anniewey
Copy link

Anyone found solution yet?

@pierroo
Copy link

pierroo commented Mar 15, 2022

I'm gonna have to ask as well: anyone found a solution yet?
related issue being: when tapping on a received notification, it doesn't open the app.

@icetee
Copy link

icetee commented Mar 18, 2022

If you download application from Play Store, you application automatically granted SYSTEM_ALERT_WINDOW permission.
https://stackoverflow.com/questions/36016369/system-alert-window-how-to-get-this-permission-automatically-on-android-6-0-an

@chanphiromsok
Copy link

chanphiromsok commented Jun 14, 2023

Hi, I found the solution to check if is it granted or not for Xiaomi device's Display window while running in the background use this OP_BACKGROUND_START_ACTIVITY to request if granted will return true else false
ref https://gist.github.com/0awawa0/65bf88e43159750f596da194ed923522

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import java.lang.reflect.Method;

// MIUI. Redefining Android.
// (not in the very best way I'd say)
public class XiaomiUtilities {

	// custom permissions
	public static final int OP_ACCESS_XIAOMI_ACCOUNT = 10015;
	public static final int OP_AUTO_START = 10008;
	public static final int OP_BACKGROUND_START_ACTIVITY = 10021;
	public static final int OP_BLUETOOTH_CHANGE = 10002;
	public static final int OP_BOOT_COMPLETED = 10007;
	public static final int OP_DATA_CONNECT_CHANGE = 10003;
	public static final int OP_DELETE_CALL_LOG = 10013;
	public static final int OP_DELETE_CONTACTS = 10012;
	public static final int OP_DELETE_MMS = 10011;
	public static final int OP_DELETE_SMS = 10010;
	public static final int OP_EXACT_ALARM = 10014;
	public static final int OP_GET_INSTALLED_APPS = 10022;
	public static final int OP_GET_TASKS = 10019;
	public static final int OP_INSTALL_SHORTCUT = 10017;
	public static final int OP_NFC = 10016;
	public static final int OP_NFC_CHANGE = 10009;
	public static final int OP_READ_MMS = 10005;
	public static final int OP_READ_NOTIFICATION_SMS = 10018;
	public static final int OP_SEND_MMS = 10004;
	public static final int OP_SERVICE_FOREGROUND = 10023;
	public static final int OP_SHOW_WHEN_LOCKED = 10020;
	public static final int OP_WIFI_CHANGE = 10001;
	public static final int OP_WRITE_MMS = 10006;

	public static boolean isMIUI() {
		return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
	}

	@SuppressLint("PrivateApi")
	private static String getSystemProperty(String key) {
		try {
			Class props = Class.forName("android.os.SystemProperties");
			return (String) props.getMethod("get", String.class).invoke(null, key);
		} catch (Exception ignore) {
		}
		return null;
	}

	@SuppressWarnings("JavaReflectionMemberAccess")
	@TargetApi(19)
	public static boolean isCustomPermissionGranted(Context context, int permission) {
		try {
			AppOpsManager mgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
			Method m = AppOpsManager.class.getMethod("checkOpNoThrow", int.class, int.class, String.class);
			int result = (int) m.invoke(mgr, permission, android.os.Process.myUid(), context.getPackageName());
			return result == AppOpsManager.MODE_ALLOWED;
		} catch (Exception e) {
			Logger.INSTANCE.log("XiaomiUtils", e.toString(), Logger.IMPORTANCE.DEFAULT, true);
		}
		return true;
	}

	public static Intent getPermissionManagerIntent(Context context) {
		Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
		intent.putExtra("extra_package_uid", android.os.Process.myUid());
		intent.putExtra("extra_pkgname", context.getPackageName());
		intent.putExtra("extra_package_name", context.getPackageName());
		return intent;
	}
}

@mianaliasjad
Copy link

I see that the background pop up window permission is granted by default for apps like Amazon Music and Airbnb. How come that's possible for them?

did you find out how they get that permission automatically?

@golubevdev
Copy link

golubevdev commented Jan 18, 2024

I see that the background pop up window permission is granted by default for apps like Amazon Music and Airbnb. How come that's possible for them?

did you find out how they get that permission automatically?

They are white-listed by OEM on MIUI, thats how they got this permission automatically

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

10 participants