Android-检查用户的位置权限选择
创始人
2024-08-19 19:00:48
0

使用运行时权限检查,可以在用户选择完位置权限之后检查用户的选择并作出相应处理。代码示例:

// check location permission
if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

    // Location permission is granted
     // Do your stuff here

} else {

    // Location permission is not granted
    // Ask for the permission
    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            MY_PERMISSIONS_REQUEST_LOCATION);

    // MY_PERMISSIONS_REQUEST_LOCATION is an
    // app-defined int constant. The callback method gets the
    // result of the request.
}

//Handle the result of permission request
@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_LOCATION: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted
                // Do your stuff here

            } else {

                // permission denied
                // Do your stuff here

            }
            return;
        }

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

相关内容

热门资讯

透视透视!wepoker辅助器... 透视透视!wepoker辅助器安装包定制,购买wepoker模拟器(透视)扑克教程(有挂揭秘);1)...
透视透视挂!wepoker能不... 透视透视挂!wepoker能不能透视,wepoker辅助器是真的吗(透视)透牌教程(有挂黑科技)所有...
透视透视挂!we poker辅... 透视透视挂!we poker辅助器v3.3,wepoker怎么买辅助(透视)专业教程(有挂解密);1...
透视智能ai!wepoker怎... 透视智能ai!wepoker怎么破解游戏,WePoKer辅助器(透视)可靠教程(有挂教程)1、首先打...
透视透视!wepoker游戏下... 透视透视!wepoker游戏下载,wepoker有辅助器吗(透视)总结教程(有挂辅助)1、wepok...
透视玄学!wepoker私人局... 透视玄学!wepoker私人局有透视吗,wepoker祈福有用吗(透视)解密教程(有挂介绍)wepo...
透视玄学!wepoker分析,... 透视玄学!wepoker分析,wepoker透视器免费(透视)AI教程(有挂方法);一、wepoke...
透视新版!wepoker底牌透... 透视新版!wepoker底牌透视,wepoker数据分析工具(透视)详细教程(有挂黑科技)1、这是跨...
透视线上!wepoker脚本下... 透视线上!wepoker脚本下载,wepoker轻量版透视方法(透视)线上教程(有挂教程);1、很好...
透视真的!wepokerplu... 透视真的!wepokerplus外挂,wepoker有透视吗(透视)透明教程(有挂工具)1、wepo...