Невозможно запустить настройки уведомлений приложения в Android Q. Он открывает настройки уведомлений с помощью этого кода.
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, activity.getPackageName());
activity.startActivity(intent);
Но я хочу выделить канал, поэтому я добавил эту строку, но в итоге получилось сбой приложения системных настроек.
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NOTIFICATION_CHANNEL_ID);
Пожалуйста, помогите, обратите внимание, что я хочу выделить указанный идентификатор канала c для пользователя, потому что у меня много других каналов уведомлений.
Process: com.android.settings, PID: 852
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.Settings$AppNotificationSettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.preference.Preference.setOnPreferenceChangeListener(androidx.preference.Preference$OnPreferenceChangeListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.preference.Preference.setOnPreferenceChangeListener(androidx.preference.Preference$OnPreferenceChangeListener)' on a null object reference
at com.android.settingslib.core.AbstractPreferenceController.displayPreference(AbstractPreferenceController.java:37)
at com.android.settings.dashboard.DashboardFragment.lambda$displayResourceTiles$5(DashboardFragment.java:313)
at com.android.settings.dashboard.-$$Lambda$DashboardFragment$Tn5-YvXfafHUTSTeQyMxdmcExvo.accept(Unknown Source:4)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:604)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:283)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:475)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:133)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:236)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:435)
at com.android.settings.dashboard.DashboardFragment.displayResourceTiles(DashboardFragment.java:312)
at com.android.settings.dashboard.DashboardFragment.refreshAllPreferences(DashboardFragment.java:360)
at com.android.settings.dashboard.DashboardFragment.onCreatePreferences(DashboardFragment.java:160)
at androidx.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:160)
at com.android.settingslib.core.lifecycle.ObservablePreferenceFragment.onCreate(ObservablePreferenceFragment.java:61)
at com.android.settings.SettingsPreferenceFragment.onCreate(SettingsPreferenceFragment.java:133)
at com.android.settings.dashboard.DashboardFragment.onCreate(DashboardFragment.java:137)
at com.android.settings.notification.NotificationSettingsBase.onCreate(NotificationSettingsBase.java:142)
at com.android.settings.notification.AppNotificationSettings.onCreate(AppNotificationSettings.java:54)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2596)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:831)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1197)
2020-04-11 20:38:26.277 852-852/? E/AndroidRuntime: at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1080)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:119)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1853)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1811)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1717)
at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManagerImpl.java:183)
at com.android.settings.SettingsActivity.switchToFragment(SettingsActivity.java:567)
at com.android.settings.SettingsActivity.launchSettingFragment(SettingsActivity.java:360)
at com.android.settings.SettingsActivity.onCreate(SettingsActivity.java:268)
at android.app.Activity.performCreate(Activity.java:7824)
at android.app.Activity.performCreate(Activity.java:7813)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
... 11 more