我在Android 8.0上面临屏幕叠加问题。下面提到的是我的manifest.xml文件中提到的权限 -
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
单击按钮(按钮位于片段内),我正在检查是否授予了WRITE_EXTERNAL_STORAGE
权限。如果没有被授予,我会做以下事情 -
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 5);
&安培;在onRequestPermissionsResult
&{ PackageManager.PERMISSION_GRANTED
我称之为逻辑部分。
但是,如果我按下权限弹出的允许或拒绝按钮,我会在整个设备屏幕上显示半透明覆盖&amp;除非我没有从后台杀死应用程序,否则它不会被删除。此外,设备后退按钮在此方案中不起作用。
每当我调用requestCode == 5
权限对话框&amp;采取其中一项行动。
如果已经授予了权限,则应用程序运行正常,没有任何重叠问题。
我的WRITE_EXTERNAL_STORAGE
&amp; minSdkVersion = 19
。
此外,我的代码中还有没有Toast消息。
我已在Android 7.0&amp ;;中测试了该应用它工作得很好。我在Android 8.0设备上遇到此问题,例如Nexus 6P / Google Pixel设备。
任何帮助将不胜感激。
提前致谢。
答案 0 :(得分:0)
试试这个我做两个单独的方法进行权限检查。
/**
* this method request to permission asked.
*/
private void requestPermissions() {
boolean shouldProvideRationale =
ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (shouldProvideRationale) {
} else {
Log.i("Error", "Requesting permission");
// previously and checked "Never ask again".
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_PERMISSIONS_REQUEST_CODE);
}
}
/**
* this method check permission and return current state of permission need.
*/
private boolean checkPermissions() {
int permissionState = ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
return permissionState == PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
if (grantResults.length <= 0) {
// If user interaction was interrupted, the permission request is cancelled and you
// receive empty arrays.
Log.i("Error", "User interaction was cancelled.");
} else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission was granted. Kick off the process of building and connecting
// GoogleApiClient.
getCallDetails();
} else {
}
}
}
然后检查了这样的主要活动。
if (!checkPermissions()) {
requestPermissions();
} else {
getWrite();
}