如何在Android中启动特定应用程序的位置设置

inkz8wg9  于 2023-05-15  发布在  Android
关注(0)|答案(2)|浏览(137)

要在Android应用程序中启用“始终允许”位置权限,如何在Android设置中启动应用程序的位置设置?
我已经看到了如何启动Android的位置设置页面(所有应用程序),以及如何启动特定应用程序的设置,但没有看到如何深入链接到特定应用程序的位置设置。
这是我目前拥有的:

fun openAppLocationSettings(context: Context) {
        val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
        val packageName = context.packageName
        val uri = Uri.fromParts("package", packageName, null)
        intent.data = uri
        context.startActivity(intent)
    }

但它只显示应用程序设置的根页面。

kwvwclae

kwvwclae1#

使用此方法,以便弹出将自动来允许所有的时间。

private void getPermission()
{

    progressBar.setVisibility(View.VISIBLE);
    ActivityResultLauncher<String[]> locationPermissionRequest =
            registerForActivityResult(new ActivityResultContracts
                            .RequestMultiplePermissions(), result -> {
                        Boolean fineLocationGranted = result.getOrDefault(
                                Manifest.permission.ACCESS_FINE_LOCATION, false);
                        Boolean coarseLocationGranted = result.getOrDefault(
                                Manifest.permission.ACCESS_COARSE_LOCATION, false);
                        if (fineLocationGranted != null && fineLocationGranted) {
                            // Call Your Method
                        } else if (coarseLocationGranted != null && coarseLocationGranted) {
                            // Only approximate location access granted.
                            // Call Your Method
                        } else {
                            // No location access granted.
                        }
                    }
            );

    locationPermissionRequest.launch(new String[] {
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION
    });
}
uelo1irk

uelo1irk2#

您可以使用以下代码在Android设置中打开位置设置:

Intent locSettings = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(locSettings);

要访问安全设置下的位置隐私设置,可以使用以下代码:

Intent locSettings = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
startActivityForResult(locSettings);

在Kotlin中:

startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))

//or 

startActivity(Intent(Settings.ACTION_SECURITY_SETTINGS))

相关问题