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

相关内容

热门资讯

微扑克德州专用辅助器!微扑克w... 微扑克德州专用辅助器!微扑克wpk真的有辅助,微扑克辅助器ios,详细教程(有挂神器)1、任何德州a...
wpk有外 挂!wpk俱乐部后... wpk有外 挂!wpk俱乐部后台管理系统(wpK)的确是有挂的-详细透视辅助教程;1、许多玩家不知道...
wepoke ai辅助!wep... wepoke ai辅助!wepoke辅助软件下载链接,wepoke辅助真的(详细辅助挂教程)是一款可...
wepoke插件!wepoke... wepoke插件!wepoke辅助透,wepoke是有软件,安装教程(有挂细节)需要回顾用户提供的搜...
微扑克辅助器ios!微扑克机制... 微扑克辅助器ios!微扑克机制技巧(透明挂)本来是有挂1、超多福利:超高返利,海量正版游戏,微扑克系...
wpk有辅助挂!wpk微扑克辅... wpk有辅助挂!wpk微扑克辅助存在(WpK)都是真的有挂-详细透明挂教程微扑克辅助器中分为三种模型...
微扑克辅助软件!德州wpk辅助... 微扑克辅助软件!德州wpk辅助,wepower有机器人(详细辅助教程);微扑克辅助软件黑科技是一款具...
wepok软件透明挂!wopo... wepok软件透明挂!wopoker轻量版外 挂(辅助挂)we辅助poker(总是真的有挂)1、很好...
微扑克全自动机器人!微扑克脚本... 您好,微扑克这款游戏可以开挂的,确实是有挂的,需要了解加微【757446909】很多玩家在这款游戏中...
WPK透视辅助!wpk脚本(W... WPK透视辅助!wpk脚本(WPK)本来真的有挂-详细透视教程;WPK辅助器中分为三种模型:WPK软...