gpt4 book ai didi

android - 如何在适配器中获得权限回调

转载 作者:行者123 更新时间:2023-11-29 15:36:23 27 4
gpt4 key购买 nike

我有一个 ArrayAdapter我需要在哪里选择图像...但首先我需要检查是否授予权限...我怎样才能获得 callback对于 OnPermissionsResult在我的适配器中。

最佳答案

首先在适配器中创建一个方法

public void getResult(Boolean value) {
if (value == true) {
//do smth
} else {
//do smth else
}
}

然后在你的 Activity 中
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case 1: {

// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay! Do the
// contacts-related task you need to do.

adapter.getResult(true); // call method via adapter instance
} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
adapter.getResult(false);
}
return;
}

// other 'case' lines to check for other
// permissions this app might request
}
}

关于android - 如何在适配器中获得权限回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48900783/

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