gpt4 book ai didi

Android M 权限关闭我的应用程序

转载 作者:可可西里 更新时间:2023-11-01 19:10:05 24 4
gpt4 key购买 nike

我在登录屏幕上检查所需的权限。该对话框显示询问我需要的 4 个权限。一切都很好,但是当对话框出现时,背景变黑并且我的应用程序关闭(不会崩溃,只是关闭)。当我完成选择权限后,我再次打开应用程序,它会从停止的地方继续运行。如何在显示权限对话框时让应用程序继续运行?我使用一个类来检查权限并在登录 Activity 中调用它。

类(class):

public abstract class RuntimePermissionsActivity extends AppCompatActivity {
private SparseIntArray mErrorString;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mErrorString = new SparseIntArray();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
int permissionCheck = PackageManager.PERMISSION_GRANTED;
for (int permission : grantResults){
permissionCheck = permissionCheck + permission;
}
if ((grantResults.length>0) && permissionCheck == PackageManager.PERMISSION_GRANTED){
onPermissionsGranted(requestCode);
}
else {

Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
}
}

public void requestAppPermissions(final String[] requestedPermissions, final int requestCode){
int stringId = 0;
mErrorString.put(requestCode, stringId);
int permissionCheck = PackageManager.PERMISSION_GRANTED;
boolean shouldShowRequestPermissionRationale = false;
for (String permission : requestedPermissions){
permissionCheck = permissionCheck + ContextCompat.checkSelfPermission(this, permission);
shouldShowRequestPermissionRationale = ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
}
if(permissionCheck != PackageManager.PERMISSION_GRANTED){
if(shouldShowRequestPermissionRationale){
ActivityCompat.requestPermissions(RuntimePermissionsActivity.this, requestedPermissions, requestCode);
}
else {
ActivityCompat.requestPermissions(this, requestedPermissions, requestCode);
Toast.makeText(RuntimePermissionsActivity.this, "Please relaunch the application in order for the changes to take effect!", Toast.LENGTH_LONG).show();
}
}
else {
onPermissionsGranted(requestCode);
}

}
public abstract void onPermissionsGranted(int requestCode);
}

登录 Activity 调用:

LoginActivity.super.requestAppPermissions(new
String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSIONS);

最佳答案

我遇到了同样的问题,请检查您的 list 文件中是否有 Activity android:noHistory="true"

关于Android M 权限关闭我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844983/

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