Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for LED and Vibrate for Android 8.0 #1684

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/android/TriggerReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import android.os.Bundle;
import android.os.PowerManager;

import java.util.Calendar;

import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification;
Expand All @@ -37,9 +35,6 @@
import static android.content.Context.POWER_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static de.appplant.cordova.plugin.localnotification.LocalNotification.fireEvent;
import static de.appplant.cordova.plugin.localnotification.LocalNotification.isAppRunning;
import static java.util.Calendar.MINUTE;

/**
* The alarm receiver is triggered when a scheduled alarm is fired. This class
Expand Down Expand Up @@ -71,21 +66,16 @@ public void onTrigger (Notification notification, Bundle bundle) {
if (options.shallWakeUp()) {
wakeUp(context);
}

manager.createDefaultChannel(options.getDict().optBoolean("led", true), options.getDict().optBoolean("vibrate", true));
notification.show();

if (!isUpdate && isAppRunning()) {
fireEvent("trigger", notification);
if (options.isInfiniteTrigger()) {
manager.schedule(new Request(options), this.getClass());
}

if (!options.isInfiniteTrigger())
return;

Calendar cal = Calendar.getInstance();
cal.add(MINUTE, 1);
Request req = new Request(options, cal.getTime());

manager.schedule(req, this.getClass());
if (!isUpdate) {
LocalNotification.fireEvent("trigger", notification);
}
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/android/notification/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* limitations under the License.
*/

// codebeat:disable[TOO_MANY_FUNCTIONS]
// codebeat:disable[TOO_MANY_FUNCTIONS]

package de.appplant.cordova.plugin.notification;

Expand Down Expand Up @@ -70,7 +70,7 @@ public final class Manager {
*/
private Manager(Context context) {
this.context = context;
createDefaultChannel();
createDefaultChannel(true,true);
}

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ public Notification schedule (Request request, Class<?> receiver) {
* TODO: temporary
*/
@SuppressLint("WrongConstant")
private void createDefaultChannel() {
public void createDefaultChannel(Boolean enablelights, Boolean enablevibration) {
NotificationManager mgr = getNotMgr();

if (SDK_INT < O)
Expand All @@ -121,7 +121,8 @@ private void createDefaultChannel() {

channel = new NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_DEFAULT);

channel.enableLights(enablelights);
channel.enableVibration(enablevibration);
mgr.createNotificationChannel(channel);
}

Expand Down Expand Up @@ -418,4 +419,4 @@ private NotificationManagerCompat getNotCompMgr() {

}

// codebeat:enable[TOO_MANY_FUNCTIONS]
// codebeat:enable[TOO_MANY_FUNCTIONS]