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私人辅助器(辅助挂)果然真的有挂(有挂方法辅助插件);1、完成有辅助插件,帮...
实测发现!hhpoker免费透... 实测发现!hhpoker免费透视脚本(辅助挂)一直是真的有挂(新版有挂辅助工具)1、起透看视 辅助软...
每日必看教程!werplan有... 每日必看教程!werplan有挂吗(辅助挂)本来是真的有挂(有挂方略辅助脚本)所有人都在同一条线上,...
必看攻略!wepoker模拟器... 必看攻略!wepoker模拟器哪个好用(辅助挂)真是有挂(有挂详细辅助脚本)运辅助工具,进入游戏界面...
重大科普!pokemmo脚本辅... 重大科普!pokemmo脚本辅助器(辅助挂)原来真的有挂(确实有挂辅助工具)1、起透看视 辅助软件价...
热点推荐!wpk透视工作室(辅... 热点推荐!wpk透视工作室(辅助挂)果然真的有挂(有挂方法辅助插件)脚本下载中分为三种模型:挂靠谱的...
今日百科!hhpoker免费透... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
玩家必知教程!hhpoker有... 玩家必知教程!hhpoker有没有辅助(辅助挂)真是存在有挂(有挂总结辅助器)1、玩家可以在线上大神...
记者揭秘!wepoker私人局... 记者揭秘!wepoker私人局规律(辅助挂)真是有挂(有挂猫腻辅助方法)1、超多福利:超高返利,海量...
一分钟了解!hhpoker有后... 一分钟了解!hhpoker有后台操作吗(辅助挂)竟然存在有挂(有挂技术辅助插件)1、金币登录送、破产...