How to add a notification settings activity to the

2019-01-23 05:13发布

On Android 5.0 there is an option through Settings -> Sound & notification -> App notification -> Calendar (for example) to go directly to the notification settings of the app.
I also know it's a flag in the manifest as described in this DEV.BYTES talk.
How can it be achieved, what is the flag used?

Here is a screenshot for more clarification:
enter image description here

2条回答
一夜七次
2楼-- · 2019-01-23 05:21
  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);
}
查看更多
爷的心禁止访问
3楼-- · 2019-01-23 05:30

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

查看更多
登录 后发表回答