Android 如何深入链接到首选项UI

Android 如何深入链接到首选项UI,android,android-preferences,android-deep-link,Android,Android Preferences,Android Deep Link,我有一个Android应用程序,它使用了Preferences UI。我希望能够深入链接到特定的首选项选项。我不知道该怎么做 我已经使用教程设置了这些首选项,如下所示 (第一部分) 我已经使用本教程设置了深度链接活动 我希望能够深入链接到一个直接的偏好 public class SettingsActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragme

我有一个Android应用程序,它使用了Preferences UI。我希望能够深入链接到特定的首选项选项。我不知道该怎么做

我已经使用教程设置了这些首选项,如下所示

  • (第一部分)
  • 我已经使用本教程设置了深度链接活动

    我希望能够深入链接到一个直接的偏好

    public class SettingsActivity extends AppCompatActivity
        implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
    {
            @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_settings);
                    FragmentFactory fragmentFactory = new AppFragmentFactory();
    
            final FragmentManager fragmentManager = getSupportFragmentManager();
            if (fragmentManager != null)
            {
                if (fragmentManager.findFragmentByTag(ROOT_FRAGMENT_TAG) == null)
                {
                    final int containerId = R.id.detail_container;
                    final Fragment fragment = fragmentFactory.create(RootPreferencesFragment.class);
                    fragment.setArguments(savedInstanceState);
                    fragmentManager.beginTransaction()
                        .add(containerId, fragment, ROOT_FRAGMENT_TAG)
                        .commit();
                }
            }
        }
    }
    
    
        @Override
        public boolean onPreferenceStartFragment(PreferenceFragmentCompat callingFragment, Preference preference)
        {
            final Bundle arguments = preference.getExtras();
            final Fragment fragment = fragmentFactory.create(getClassLoader(), preference.getFragment());
            fragment.setArguments(arguments);
            fragment.setTargetFragment(callingFragment, 0);
    
            getSupportFragmentManager().beginTransaction()
                .replace(R.id.detail_container, fragment)
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .setBreadCrumbTitle(preference.getTitle())
                .addToBackStack(preference.getKey())
                .commit();
            return true;
        }
    
    根优先片段

    public class RootPreferencesFragment extends PreferenceFragmentCompat implements DialogFragmentCallback
    {
        @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
    {
        final FragmentActivity activity = Objects.requireNonNull(getActivity());
    
            // Notifications
        final Preference notificationsPreference = preferencesFactory.create(
            accountCategory,
            Preference.class,
            RootViewModel.ACCOUNT_NOTIFICATIONS_PREFERENCE_KEY,
            R.string.PushNotifications,
            RootViewModel.ACCOUNT_CATEGORY_KEY);
        notificationsPreference.setFragment(NotificationPreferencesFragment.class.getName());
    
    
        // General Category
        final PreferenceCategory generalCategory = preferencesFactory.create(
            preferenceScreen,
            PreferenceCategory.class,
            RootViewModel.GENERAL_CATEGORY_KEY,
            R.string.preferences_general_group);
    
    
        // About category
        final PreferenceCategory aboutCategory = preferencesFactory.create(
            preferenceScreen,
            PreferenceCategory.class,
            RootViewModel.ABOUT_CATEGORY_KEY,
            R.string.preferences_about_group);
    
        // About
        final Preference aboutPreference = preferencesFactory.create(
            aboutCategory,
            Preference.class,
            RootViewModel.ABOUT_PREFERENCE_KEY,
            R.string.preferences_about);
        aboutPreference.setSummary(aboutViewModel.getAppVersion());
        aboutPreference.setFragment(AboutPreferencesFragment.class.getName());
    }
    }
    
    我不知道如何触发到特定通知参考的深度链接。只有一个活动,但有三个首选项

    public class SettingsActivity extends AppCompatActivity
        implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
    {
            @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_settings);
                    FragmentFactory fragmentFactory = new AppFragmentFactory();
    
            final FragmentManager fragmentManager = getSupportFragmentManager();
            if (fragmentManager != null)
            {
                if (fragmentManager.findFragmentByTag(ROOT_FRAGMENT_TAG) == null)
                {
                    final int containerId = R.id.detail_container;
                    final Fragment fragment = fragmentFactory.create(RootPreferencesFragment.class);
                    fragment.setArguments(savedInstanceState);
                    fragmentManager.beginTransaction()
                        .add(containerId, fragment, ROOT_FRAGMENT_TAG)
                        .commit();
                }
            }
        }
    }
    
    
        @Override
        public boolean onPreferenceStartFragment(PreferenceFragmentCompat callingFragment, Preference preference)
        {
            final Bundle arguments = preference.getExtras();
            final Fragment fragment = fragmentFactory.create(getClassLoader(), preference.getFragment());
            fragment.setArguments(arguments);
            fragment.setTargetFragment(callingFragment, 0);
    
            getSupportFragmentManager().beginTransaction()
                .replace(R.id.detail_container, fragment)
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .setBreadCrumbTitle(preference.getTitle())
                .addToBackStack(preference.getKey())
                .commit();
            return true;
        }