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

相关内容

热门资讯

今日科普!we-poker靠谱... 今日科普!we-poker靠谱吗,wpk控制牌是真的吗,好像真的是有挂(有挂教学)一、可以开透视的定...
重大通报!德州局脚本,hhpo... 重大通报!德州局脚本,hhpoker万能辅助器,真是是有挂(今日头条)1、全新机制【ai辅助工具激活...
分享一款!wepoker作弊方... 分享一款!wepoker作弊方法,德州透视竞技联盟,切实是真的有挂(确实有挂)1、公共底牌简单,透视...
记者揭秘!wepoker辅助透... 记者揭秘!wepoker辅助透视,xpoker辅助怎么用,其实存在有挂(证实有挂)1、首先打开wep...
我来教大家!hhpoker视频... 我来教大家!hhpoker视频巡查真的假的,hhpoker德州有挂吗,真是有挂(有挂教程)1、点击下...
六分钟了解!德普之星透视辅助软... 六分钟了解!德普之星透视辅助软件,wepoker俱乐部辅助,果然是真的有挂(有挂透视)1、模拟器是什...
攻略讲解!聚星ai辅助工具收费... 攻略讲解!聚星ai辅助工具收费多少,悟空黑桃a辅助,果然有挂(有挂猫腻)脚本下载中分为三种模型:挂靠...
解密关于!德扑之心免费透视,德... 解密关于!德扑之心免费透视,德州hhpoker脚本,本来有挂(有挂细节)1、公共底牌简单,透视插件操...
最新研发!wepoker辅助真... 最新研发!wepoker辅助真的假的,pokemmo免费脚本,原来是真的有挂(有挂规律)1、起透看视...
科技通报!wpk俱乐部辅助器,... 科技通报!wpk俱乐部辅助器,werplan免费挂下载,好像真的是有挂(有挂细节)1、进入到是否有挂...