gpt4 book ai didi

android - fine_location 权限 android 的常量

转载 作者:行者123 更新时间:2023-11-29 02:39:40 25 4
gpt4 key购买 nike

我搜索了如何初始化 requestPermissions 并找到了以下代码:

if (ActivityCompat.checkSelfPermission((Activity)mContext, 
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity)mContext, new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION
}, Integer constant required);

它需要第三个参数,它是 FINE LOCATION 的 Inter 常量。我找不到那个。请帮我解决这个问题。

最佳答案

第三个参数是权限的requestCode,你可以创建它常量像下面一样

private int STORAGE_PERMISSION_CODE = 23; //you can pass any code here
ActivityCompat.requestPermissions((Activity)mContext, new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION}, STORAGE_PERMISSION_CODE);

该参数用于在重写时与onRequestPermissionsResult方法第一个参数的requestCode进行比较。

   @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//Checking the request code of our request
if (requestCode == STORAGE_PERMISSION_CODE) {

//If permission is granted
if (grantResults.length > 0 && grantResults[0] == 0) {

//Displaying a toast
Toast.makeText(context, "Permission granted now.", Toast.LENGTH_LONG).show();
} else {
//Displaying another toast if permission is not granted
Toast.makeText(context, "Permission denied.",Toast.LENGTH_LONG).show();
}
}
}

关于android - fine_location 权限 android 的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45081579/

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