How to add a notification settings activity to the system settings

前端 未结 2 1417
清歌不尽
清歌不尽 2020-12-15 07:37

On Android 5.0 there is an option through Settings -> Sound & notification -> App notification -> Calendar (for example) to go directly to the noti

相关标签:
2条回答
  • 2020-12-15 08:21

    You need to add the Intent category Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES to the Activity you'd like to launch through your AndroidManifest. A simple example would be something like:

        <activity android:name="com.example.packagename.YourSettingsActivity" >
    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
            </intent-filter>
        </activity>
    

    For more information, refer to the Settings app and specifically the NotificationAppList and AppNotificationSettings fragments.

    Results

    example

    0 讨论(0)
  • 2020-12-15 08:27
      public void goToPushSettingPage(Context context){
        Intent intent=new Intent();
        if(android.os.Build.VERSION.SDK_INT>Build.VERSION_CODES.N_MR1){
            intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
            intent.putExtra(Settings.EXTRA_APP_PACKAGE,context.getPackageName());
        }else if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            intent.putExtra(ConstUtil.PUSH_SETTING_APP_PACKAGE,context.getPackageName());
            intent.putExtra(ConstUtil.PUSH_SETTING_APP_UID,context.getApplicationInfo().uid);
        }else{
            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setData(Uri.parse(ConstUtil.PUSH_SETTING_URI_PACKAGE+context.getPackageName()));
        }
        startActivity(intent);
    }
    
    0 讨论(0)
提交回复
热议问题