[英]Runtime permission for SYSTEM_ALERT_WINDOW
I need to get the user permissions automatically for the following permissions while user opens the app for the first time当用户第一次打开应用程序时,我需要自动获取用户权限以获得以下权限
Phone is working fine.电话工作正常。 How to get the always on top permission
如何获得始终处于最高权限的权限
MainActivity主要活动
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);
}
Manifest显现
<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" />
there is no runtime permission/dialog for this purpose, you have to pass user to app settings没有为此目的的运行时权限/对话框,您必须将用户传递给应用程序设置
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.