gpt4 book ai didi

android - 图像裁剪许可后的 onSuccessListner

转载 作者:行者123 更新时间:2023-11-29 18:42:32 24 4
gpt4 key购买 nike

我正在像这样裁剪图像:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);

//do some activity based on permission granted or declined.
} else {
CropImage.activity(mainImageURI)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1,1)
.setAutoZoomEnabled(false)
.start(this);

;


}

}

我的问题是我想在授予或拒绝许可后立即进行一些 Activity 。在当前情况下,我可以先授予权限,然后再次单击我正在使用的 ImageView ,然后再进行裁剪。但是我想在授予权限后立即进行一项 Activity ,如果权限被拒绝则进行一项 Activity 。

最佳答案

您应该在您的 Activity 中覆盖 onRequestPermissionsResult,以便在授予或未授予权限时收到通知:

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == PERMISSIONS_CODE) {
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
int grantResult = grantResults[i];

if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (grantResult == PackageManager.PERMISSION_GRANTED) {
// TODO Open The Crop Activity
} else {
// TODO Tell the user your app can't function properly
}
}
}
}
}

关于android - 图像裁剪许可后的 onSuccessListner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52799456/

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