-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
v0.10.0; multiple Android and iOS fixes #2000
base: master
Are you sure you want to change the base?
Changes from 20 commits
ccad06f
6576b38
083ccca
8a2f0c7
7d81d24
9a5c4a9
00c8228
953adb3
c1696bd
6bcacac
69faa3a
d6fcc37
db99ddd
de99069
3bc3f0d
c194111
a3b5d5f
2832b96
0275c59
f618d3a
3f3fb30
93ffd5a
c2ee2d1
8a67e65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
* Apache 2.0 License | ||
* | ||
* Copyright (c) Sebastian Katzer 2017 | ||
* Contributors Bhumin Bhandari, fquirin, powowbox and many more: | ||
* https://github.com/katzer/cordova-plugin-local-notifications/graphs/contributors | ||
* | ||
* This file contains Original Code and/or Modifications of Original Code | ||
* as defined in and that are subject to the Apache License | ||
|
@@ -24,7 +26,7 @@ | |
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
id="cordova-plugin-local-notification" | ||
version="0.9.0-beta.4"> | ||
version="0.10.0"> | ||
|
||
<name>LocalNotification</name> | ||
|
||
|
@@ -36,21 +38,19 @@ | |
|
||
<license>Apache 2.0</license> | ||
|
||
<author>Sebastián Katzer</author> | ||
<author>Sebastián Katzer, fquirin, Bhumin Bhandari, powowbox and more</author> | ||
|
||
<!-- cordova --> | ||
<engines> | ||
<engine name="cordova" version=">=7.1.0" /> | ||
<engine name="cordova-plugman" version=">=4.3.0" /> | ||
<engine name="cordova-android" version=">=6.3.0" /> | ||
<engine name="cordova-windows" version=">=4.2.0" /> | ||
<!-- <engine name="android-sdk" version=">=26" /> --> | ||
<engine name="apple-ios" version=">=10.0.0" /> | ||
<engine name="cordova" version=">=9.0.0"/> | ||
<engine name="cordova-android" version=">=9.0.0"/> | ||
<engine name="cordova-ios" version=">=6.0.0"/> | ||
<engine name="cordova-windows" version=">=4.2.0"/> | ||
</engines> | ||
|
||
<!-- dependencies --> | ||
<dependency id="cordova-plugin-device" /> | ||
<dependency id="cordova-plugin-badge" version=">=0.8.5" /> | ||
<dependency id="cordova-plugin-badge-fix" version=">=0.8.10"/><!-- TODO: return to 'cordova-plugin-badge' when fixed --> | ||
|
||
<!-- js --> | ||
<js-module src="www/local-notification.js" name="LocalNotification"> | ||
|
@@ -93,6 +93,11 @@ | |
<preference name="ANDROID_SUPPORT_V4_VERSION" default="26.+" /> | ||
<framework src="com.android.support:support-v4:$ANDROID_SUPPORT_V4_VERSION" /> | ||
<framework src="src/android/build/localnotification.gradle" custom="true" type="gradleReference"/> | ||
<!-- android x --> | ||
<preference name="ANDROIDX_VERSION" default="1.2.0" /> | ||
<preference name="ANDROIDX_APPCOMPAT_VERSION" default="1.3.1" /> | ||
|
||
<framework src="androidx.appcompat:appcompat:$ANDROIDX_APPCOMPAT_VERSION" /> | ||
|
||
<config-file target="res/xml/config.xml" parent="/*"> | ||
<feature name="LocalNotification"> | ||
|
@@ -119,9 +124,10 @@ | |
android:name="de.appplant.cordova.plugin.localnotification.ClearReceiver" | ||
android:exported="false" /> | ||
|
||
<service | ||
<activity | ||
android:name="de.appplant.cordova.plugin.localnotification.ClickReceiver" | ||
android:exported="false" /> | ||
android:exported="false" | ||
android:theme="@style/Theme.AppCompat.NoActionBar"/> | ||
|
||
<receiver | ||
android:name="de.appplant.cordova.plugin.localnotification.RestoreReceiver" | ||
|
@@ -138,6 +144,8 @@ | |
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> | ||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
<uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> | ||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Schedule exact alarm is no longer allowed on android 13 for non alarm apps. https://developer.android.com/about/versions/14/changes/schedule-exact-alarms#calendar-alarm-clock) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have do it in a separate PR. |
||
</config-file> | ||
|
||
<source-file | ||
|
@@ -192,6 +200,10 @@ | |
src="src/android/notification/receiver/AbstractTriggerReceiver.java" | ||
target-dir="src/de/appplant/cordova/plugin/notification/receiver" /> | ||
|
||
<source-file | ||
src="src/android/notification/receiver/NotificationTrampolineActivity.java" | ||
target-dir="src/de/appplant/cordova/plugin/notification/receiver" /> | ||
|
||
<source-file | ||
src="src/android/notification/trigger/DateTrigger.java" | ||
target-dir="src/de/appplant/cordova/plugin/notification/trigger" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Apache 2.0 License | ||
* | ||
* Copyright (c) Sebastian Katzer 2017 | ||
* Contributor Bhumin Bhandari | ||
fquirin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* This file contains Original Code and/or Modifications of Original Code | ||
* as defined in and that are subject to the Apache License | ||
|
@@ -40,6 +41,12 @@ | |
import android.util.Pair; | ||
import android.view.View; | ||
|
||
import android.app.NotificationManager; | ||
import android.app.NotificationChannel; | ||
import android.app.PendingIntent; | ||
import androidx.core.app.NotificationCompat; | ||
import android.content.Intent; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.CordovaInterface; | ||
import org.apache.cordova.CordovaPlugin; | ||
|
@@ -185,13 +192,52 @@ public void run() { | |
isIgnoringBatteryOptimizations(command); | ||
} else if (action.equals("requestIgnoreBatteryOptimizations")) { | ||
requestIgnoreBatteryOptimizations(command); | ||
} else if (action.equals("dummyNotifications")) { | ||
dummyNotifications(command); | ||
} | ||
} | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Required for Android 13 to get the runtime notification permissions. | ||
* | ||
* @param command The callback context used when calling back into JavaScript. | ||
*/ | ||
private void dummyNotifications(CallbackContext command) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is just creating a channel and should be renamed to reflect this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is not optimal, though I'd prefer to merge this first before revisiting the purpose of this function |
||
|
||
fireEvent("dummyNotifications"); | ||
NotificationManager mNotificationManager; | ||
NotificationCompat.Builder mBuilder; | ||
String NOTIFICATION_CHANNEL_ID = "10004457"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this channel-Id? It should be configurable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It uses 'channeId' now from custom or default options. Only if this is not defined it falls back to the old ID (I have no idea why this ID was chosen by the other contributer). |
||
String notificationMsg = "Test"; | ||
String notificationTitle = "Mdd"; | ||
fquirin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Context context = cordova.getActivity().getApplicationContext(); | ||
|
||
Intent intentToLaunch = new Intent(context, TriggerReceiver.class); | ||
intentToLaunch.putExtra("Callfrom", "reminders"); | ||
|
||
final PendingIntent resultPendingIntent = PendingIntent.getActivity(context, | ||
0, intentToLaunch, PendingIntent.FLAG_IMMUTABLE); | ||
|
||
mBuilder = new NotificationCompat.Builder(context,NOTIFICATION_CHANNEL_ID); | ||
mBuilder.setContentIntent(resultPendingIntent); | ||
|
||
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has only an effect on android >= 8. The code above should be moved in this if-statement, because it has no effect, if the if-statement is not executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved it inside the if-case |
||
int importance = NotificationManager.IMPORTANCE_HIGH; | ||
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is creating a Channel with the name "NOTIFICATION_CHANNEL_NAME" in Android >= 8. The channel name should be configurable or should use the same logic as creating a normal notification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be fixed now, because I've added a new argument for 'options' (merged with plugin default options) |
||
assert mNotificationManager != null; | ||
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID); | ||
mNotificationManager.createNotificationChannel(notificationChannel); | ||
} | ||
|
||
command.success(); | ||
} | ||
|
||
/** | ||
* Determine if do not disturb permissions have been granted | ||
* | ||
|
@@ -701,7 +747,7 @@ static void fireEvent(String event, Notification toast, JSONObject data) { | |
sendJavascript(js); | ||
} | ||
|
||
/** | ||
/** | ||
* Use this instead of deprecated sendJavascript | ||
* | ||
* @param js JS code snippet as string. | ||
|
@@ -713,12 +759,17 @@ private static synchronized void sendJavascript(final String js) { | |
return; | ||
} | ||
|
||
if (!deviceready || webView == null) { | ||
eventQueue.add(js); | ||
return; | ||
} | ||
|
||
final CordovaWebView view = webView.get(); | ||
|
||
((Activity) (view.getContext())).runOnUiThread(new Runnable() { | ||
public void run() { | ||
view.loadUrl("javascript:" + js); | ||
View engineView = view.getEngine().getView(); | ||
View engineView = view.getEngine() != null ? view.getEngine().getView() : view.getView(); | ||
|
||
if (!isInForeground()) { | ||
engineView.dispatchWindowVisibilityChanged(View.VISIBLE); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder: it points to 'cordova-plugin-badge-fix' for the time being