SYSTEM_ALERT_WINDOW 的运行时权限
Runtime permission for SYSTEM_ALERT_WINDOW
我需要在用户首次打开应用时自动获取以下权限的用户权限
- Phone
- 通话记录
- 总在最前面
Phone 工作正常。如何获得永远在最前面的权限
主要活动
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);
}
清单
<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" />
没有用于此目的的运行时permission/dialog,您必须将用户传递给应用程序设置
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
}
更多信息
我需要在用户首次打开应用时自动获取以下权限的用户权限
- Phone
- 通话记录
- 总在最前面
Phone 工作正常。如何获得永远在最前面的权限
主要活动
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);
}
清单
<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" />
没有用于此目的的运行时permission/dialog,您必须将用户传递给应用程序设置
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
}
更多信息