diff --git a/README.md b/README.md index 41a0314..89fc904 100644 --- a/README.md +++ b/README.md @@ -121,4 +121,7 @@ AndroidOpenSettings.deviceInfoSettings() // Open application notification settings menu AndroidOpenSettings.appNotificationSettings() + +// Open application notification channel settings menu +AndroidOpenSettings.appNotificationChannelSettings(channelId) ``` diff --git a/android/src/main/java/com/levelasquez/androidopensettings/AndroidOpenSettings.java b/android/src/main/java/com/levelasquez/androidopensettings/AndroidOpenSettings.java index 97f57a9..1a9e2b9 100644 --- a/android/src/main/java/com/levelasquez/androidopensettings/AndroidOpenSettings.java +++ b/android/src/main/java/com/levelasquez/androidopensettings/AndroidOpenSettings.java @@ -1,8 +1,11 @@ package com.levelasquez.androidopensettings; +import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.provider.Settings; +import android.content.pm.PackageManager; +import android.os.Build; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; @@ -32,7 +35,7 @@ public void generalSettings() { reactContext.startActivity(intent); } } - + @ReactMethod public void homeSettings() { Intent intent = new Intent(Settings.ACTION_HOME_SETTINGS); @@ -231,4 +234,17 @@ public void appNotificationSettings() { reactContext.startActivity(intent); } } + + @ReactMethod + public void appNotificationChannelSettings(String channelId) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && channelId != null) { + Activity activity = getCurrentActivity(); + Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); + intent.putExtra(Settings.EXTRA_APP_PACKAGE, activity.getPackageName()); + intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId); + if (activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) { + activity.startActivity(intent); + } + } + } } diff --git a/index.js b/index.js index 2d6156d..dcefb9c 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,8 @@ const deviceInfoSettings = () => RNAndroidOpenSettings.deviceInfoSettings() const appNotificationSettings = () => RNAndroidOpenSettings.appNotificationSettings() +const appNotificationChannelSettings = (channelId) => RNAndroidOpenSettings.appNotificationChannelSettings(channelId) + module.exports = { generalSettings, homeSettings, @@ -63,4 +65,5 @@ module.exports = { applicationSettings, deviceInfoSettings, appNotificationSettings, + appNotificationChannelSettings, }