gpt4 book ai didi

android - 询问多个权限 Android

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:36:21 28 4
gpt4 key购买 nike

我正在修改现有的面部跟踪器应用 Android 的面部识别示例项目。我在请求多个永久权限时遇到问题。下面的方法是现有方法的修改版本,它成功地创建了一个弹出窗口来请求相机权限。我正在尝试使用存储权限复制它,但到目前为止我一直没有成功,我不确定这里需要更改什么。

 private void requestAllPermissions() {
Log.w(TAG, "Camera + Storage permissions are not granted. Requesting permissions");

final String[] permissions = new String[]{Manifest.permission.CAMERA};
final String[] permissions2 = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};


if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
ActivityCompat.requestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM);
return;
}

//new
if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
ActivityCompat.requestPermissions(this, permissions2, RC_HANDLE_STORAGE_PERM);
return;
}


final Activity thisActivity = this;

View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(thisActivity, permissions,
RC_HANDLE_CAMERA_PERM);
}
};

View.OnClickListener listener2 = new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(thisActivity, permissions2,
RC_HANDLE_STORAGE_PERM);
}
};

Snackbar.make(mGraphicOverlay, R.string.permission_camera_rationale,
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.ok, listener)
.show();

Snackbar.make(mGraphicOverlay, R.string.permission_storage_rationale,
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.ok, listener2)
.show();
}

最佳答案

如果你想在一个对话框中询问所有权限,你应该只有一个字符串数组,如下所示:

int ALL_PERMISSIONS = 101;

final String[] permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};

ActivityCompat.requestPermissions(this, permissions, ALL_PERMISSIONS);

关于android - 询问多个权限 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467618/

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