Skip to content

Commit

Permalink
Added openNotificationSettings method
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBriglio committed Jul 28, 2020
1 parent 5a4f17d commit d19207c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0 - 28-07-2020

- Added `openNotificationSettings` method

## 1.1.0 - 14-07-2020

- Added `getVersionInfo` method
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This plugin is built as a general tool utility to perform relatively small tasks
- [getNotificationChannels()](#getNotificationChannels)
- [getNotificationChannel()](#getNotificationChannel)
- [getNotificationSettings()](#getNotificationSettings)
- [openNotificationSettings()](#openNotificationSettings)
- [Questions](#Questions?)
- [License](#License)

Expand Down Expand Up @@ -143,6 +144,12 @@ cordova.plugins.android.utility.getNotificationSettings()
.catch(message => console.log('Error: ' + message))
```

### openNotificationSettings

`Usage: cordova.plugins.android.utility.openNotificationSettings()`

Open the Android OS notification settings page corresponding to the current application. This method takes no parameters and does not return any values.

---

## Questions?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-android-utility",
"version": "1.1.0",
"version": "1.2.0",
"description": "Cordova Android general utility plugin.",
"cordova": {
"id": "cordova-plugin-android-utility",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-android-utility" version="1.1.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-android-utility" version="1.2.0">
<name>Cordova Android Utility</name>
<description>Cordova Android general utility plugin.</description>
<license>MIT</license>
Expand Down
15 changes: 15 additions & 0 deletions src/UtilityPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.davidbriglio.utility;

import android.content.Context;
import android.content.Intent;
import android.app.NotificationManager;
import androidx.core.app.NotificationManagerCompat;
import android.app.NotificationChannel;
Expand Down Expand Up @@ -94,6 +95,20 @@ public boolean execute(final String action, final JSONArray args, final Callback
payload.put("securityPatch", android.os.Build.VERSION.SECURITY_PATCH);

callbackContext.success(payload);
} else if (action.equals("openNotificationSettings")) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

//for Android 5-7
intent.putExtra("app_package", mContext.getPackageName());
intent.putExtra("app_uid", mContext.getApplicationInfo().uid);

// for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", mContext.getPackageName());

mContext.startActivity(intent);
callbackContext.success();
} else {
callbackContext.error("Invalid plugin action");
}
Expand Down
3 changes: 2 additions & 1 deletion www/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
getNotificationChannel: id => new Promise((resolve, reject) => exec(resolve, reject, 'UtilityPlugin', 'getNotificationChannel', [id || ''])),
getNotificationChannels: () => new Promise((resolve, reject) => exec(resolve, reject, 'UtilityPlugin', 'getNotificationChannels', [])),
getNotificationSettings: () => new Promise((resolve, reject) => exec(resolve, reject, 'UtilityPlugin', 'getNotificationSettings', [])),
getVersionInfo: () => new Promise((resolve, reject) => exec(resolve, reject, 'UtilityPlugin', 'getVersionInfo', []))
getVersionInfo: () => new Promise((resolve, reject) => exec(resolve, reject, 'UtilityPlugin', 'getVersionInfo', [])),
openNotificationSettings: () => exec(null, null, 'UtilityPlugin', 'openNotificationSettings', [])
};

0 comments on commit d19207c

Please sign in to comment.