V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
UserANullPointer
V2EX  ›  Android

华为的定位权限(“您的位置”或者“读取位置信息”)怎么检测

  •  
  •   UserANullPointer · Oct 11, 2018 · 13563 views
    This topic created in 2762 days ago, the information mentioned may be changed or developed.
    华为 Android 系统中,应用的定位权限(“您的位置”或者“读取位置信息”)怎么检测。
    我使用下面四个方法检测
    PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
    PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
    ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)
    ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)
    结果开关权限后都是
    true
    true
    false
    false
    2 replies    2018-10-12 15:21:20 +08:00
    ysc3839
        1
    ysc3839  
       Oct 12, 2018 via Android
    估计是通过 AppOps 实现的,检测不了。
    xiaohei233
        2
    xiaohei233  
       Oct 12, 2018
    checkSelfPermission:这个函数返回是用户是否有这个权限。
    shouldShowRequestPermissionRationale:这个是判断用户是否选择了“不再询问”这个,如果用户没有这个权限或者拒绝了这个权限但是没有选中“不再询问”都是返回 false,只有选择“不在询问”才会返回 true。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2658 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 04:05 · PVG 12:05 · LAX 21:05 · JFK 00:05
    ♥ Do have faith in what you're doing.