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.
    }
}

相关内容

热门资讯

透视好牌!德州之星扫描器(透视... 透视好牌!德州之星扫描器(透视)其实存在有挂(详细辅助必赢教程);1、进入游戏-大厅左侧-新手福利-...
我来教大家!德普之星透视辅助软... 我来教大家!德普之星透视辅助软件下载,hhpoker外挂靠谱吗,可靠教程(有挂技巧)科技教程也叫必备...
透视安装!约局吧开挂(透视)竟... 透视安装!约局吧开挂(透视)竟然是真的有挂(详细辅助透牌教程)1、系统规律教程、辅助透视等服务,为用...
发现玩家!有没有人wepoke... 发现玩家!有没有人wepoker,德扑圈有透视吗,插件教程(有挂方法);最新版2024是一款经典耐玩...
透视存在!sohoo辅助(透视... 透视存在!sohoo辅助(透视)一直真的有挂(详细辅助详细教程)1、在ai机器人技巧中,中转单元十分...
推荐攻略!hhpoker透视脚... 推荐攻略!hhpoker透视脚本下载,佛手大菠萝有挂吗,规律教程(有挂方法);最新版2024是一款经...
透视中牌率!werplan怎么... 透视中牌率!werplan怎么透视(透视)一直真的有挂(详细辅助攻略方法);1、实时开挂更新:用户可...
实测分享!约局吧德州真的有透视... 《实测分享!约局吧德州真的有透视挂吗,aapoker怎么选牌,插件教程(有挂软件)》 约局吧德州真的...
透视辅助!红龙poker辅助平... 透视辅助!红龙poker辅助平台(透视)好像真的有挂(详细辅助透牌教程);1、让任何用户在无需红龙p...
盘点几款!wepoker看底牌... 盘点几款!wepoker看底牌,wepoker模拟器哪个好用,技巧教程(有挂透明);实战中需综合运用...