小编Unk*_*scl的帖子

onRequestPermissionsResult 在 Android Fragment 中已弃用

这是我当前(已弃用)的方法:

int LOCATION_REQUEST_CODE = 10001;     
@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        if (requestCode == LOCATION_REQUEST_CODE) {
            //Permission granted
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                checkSettingsAndStartLocationUpdates();
            } else {
                //DO SOMETHING - Permission not granted
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

根据android文档https://developer.android.com/training/basics/intents/result我应该使用registerForActivityResult():

// GetContent creates an ActivityResultLauncher<String> to allow you to pass
// in the mime type you'd like to allow the user to select
ActivityResultLauncher<String> mGetContent = registerForActivityResult(new GetContent(),
    new ActivityResultCallback<Uri>() { …
Run Code Online (Sandbox Code Playgroud)

java gps android location

3
推荐指数
1
解决办法
5733
查看次数

标签 统计

android ×1

gps ×1

java ×1

location ×1