Open application settings with Navigation Component

42 Views Asked by At

How to open application Settings page using Android Navigation Component?

I can open application Settings from code by sending Intent with URI of my application package name:

val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri = Uri.fromParts("package", getPackageName(), null)
intent.data = uri
startActivity(intent)

How to do the same thing but using Android Navigation Component?

1

There are 1 best solutions below

0
eugeneek On

android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS is equals to android.settings.APPLICATION_DETAILS_SETTINGS String. And package URL is just your application package (applicationId) with package: scheme: package:com.example.application

  1. Create activity tag inside navigation graph with corresponding intent action and data.

    <activity
        android:id="@+id/app_settings"
        app:action="android.settings.APPLICATION_DETAILS_SETTINGS"
        app:data="package:com.example.application"
    />
    
  2. Create action tag inside navigation graph with previously created activity

    <action
        android:id="@+id/action_global_to_app_settings"
        app:destination="@id/app_settings"
    />
    
  3. Navigate to created action with Navigation Component

    navController.navigate(NavGraphDirections.actionGlobalToAppSettings())