QT 安卓 悬浮窗权限动态申请
一:申请方式:
String ACTION_MANAGE_OVERLAY_PERMISSION = "android.settings.action.MANAGE_OVERLAY_PERMISSION";
Intent intent = new Intent(ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent,5004);
二:重载方法监听Intent返回值:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 当otherActivity中返回数据的时候,会响应此方法
// requestCode和resultCode必须与请求startActivityForResult()和返回setResult()的时候传入的值一致。
if(Settings.canDrawOverlays(this.m_instance))
{
StartVoiceInit();
}else
{
//如果没有赋予权限则强制赋权
String ACTION_MANAGE_OVERLAY_PERMISSION = "android.settings.action.MANAGE_OVERLAY_PERMISSION";
Intent intent = new Intent(ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent,5004);
}
}