gpt4 book ai didi

android - SYSTEM_ALERT_WINDOW 的运行时权限

转载 作者:行者123 更新时间:2023-12-05 08:39:52 28 4
gpt4 key购买 nike

我需要在用户第一次打开应用时自动获取以下权限

  1. 电话
  2. 通话记录
  3. 永远在最前面

电话工作正常。如何获得永远在最前面的权限

主要 Activity

protected void onCreate(Bundle savedInstanceState) {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.SYSTEM_ALERT_WINDOW)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.SYSTEM_ALERT_WINDOW}, 1);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

list

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

最佳答案

没有用于此目的的运行时权限/对话框,您必须将用户传递给应用程序设置

public boolean checkStartPermissionRequest() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE);
return false; // above will start new Activity with proper app setting
}
}
return true; // on lower OS versions granted during apk installation
}

更多信息 HERE

关于android - SYSTEM_ALERT_WINDOW 的运行时权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58604962/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com