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

Fixs pending Intent issue on Godot 3.5 #32

Open
wants to merge 5 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
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ Add wrapper `scripts/localnotification.gd` into autoloading list in your project

## API

### show(message: String, title: String, interval: float, tag: int, repeating_interval: int = 0)
### showLocalNotification(message: String, title: String, interval: float, tag: int)

Show notification with `title` and `message` after delay of `interval` seconds with `tag`. You can override notification by it's tag before it was fired.
If you defined `repeating_interval` the notification will be fired in a loop until you cancelled it.

### show_daily(message: String, title: String, hour: int, minute: int, tag: int = 1)
### showRepeatingNotification(message: String, title: String, interval: float, tag: int, repeat_duration: int)
Show notification with `title` and `message` after delay of `interval` seconds with `tag`. You can override notification by it's tag before it was fired.
`repeating_interval` the notification will be fired in a loop until you cancelled it.


### show_daily(message: String, title: String, hour: int, minute: int, tag: int = 1)
(IOS Only)
Show notification daily at specific hour and minute (in 24 hour format).
You can overide the notification with new time, or cancel it with tag and register a new one.

*Need help*: Currently just support ios, need help on Android

### cancel(tag: int)
### cancelLocalNotification(tag: int)

Cancel previously created notification.

### cancel_all()
### cancelAllNotifications()

Cancel all pending notifications (implemented for iOS only).

Expand All @@ -50,7 +54,7 @@ Check if notification permission was granted by user (iOS only).

### register_remote_notification()

Request system token for push notifications.
Request system token for push notifications. (iOS only)

### get_device_token() -> String

Expand Down
17 changes: 9 additions & 8 deletions android-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
compileSdkVersion 33
buildToolsVersion "32.0.0"

defaultConfig {
minSdkVersion 18
targetSdkVersion 29
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0"
versionName "1.1"
}

// Used to customize the name of generated AAR file.
Expand All @@ -47,8 +47,9 @@ dependencies {
necessary since the Godot editor will also provide a version of the godot
library when building the final binary.
*/
compileOnly fileTree(dir: 'libs', include: ['godot-lib*.aar'])
implementation 'io.github.m4gr3d:godot:3.5.1.stable'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.work:work-runtime:2.7.1'
}

group = 'ru.mobilap.godot'
Expand Down
1 change: 1 addition & 0 deletions android-plugin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<receiver android:name="ru.mobilap.localnotification.LocalNotificationReceiver" android:process=":remote" />
</application>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.Calendar;

import org.godotengine.godot.plugin.UsedByGodot;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -74,18 +76,18 @@ public View onMainCreate(Activity activity) {
}

// Public methods

@UsedByGodot
public void init() {
}

@UsedByGodot
public boolean isInited() {
return true;
}

@UsedByGodot
public boolean isEnabled() {
return true;
}

@UsedByGodot
public void showLocalNotification(String message, String title, int interval, int tag) {
if(interval <= 0) return;
Log.d(TAG, "showLocalNotification: "+message+", "+Integer.toString(interval)+", "+Integer.toString(tag));
Expand All @@ -102,7 +104,7 @@ public void showLocalNotification(String message, String title, int interval, in
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
}
}

@UsedByGodot
public void showRepeatingNotification(String message, String title, int interval, int tag, int repeat_duration) {
if(interval <= 0) return;
Log.d(TAG, "showRepeatingNotification: "+message+", "+Integer.toString(interval)+", "+Integer.toString(tag)+" Repeat after: "+Integer.toString(repeat_duration));
Expand All @@ -119,20 +121,20 @@ public void showRepeatingNotification(String message, String title, int interval
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), repeat_duration*1000, sender);
}
}

@UsedByGodot
public void cancelLocalNotification(int tag) {
AlarmManager am = (AlarmManager)getActivity().getSystemService(getActivity().ALARM_SERVICE);
PendingIntent sender = getPendingIntent("", "", tag);
am.cancel(sender);
}

@UsedByGodot
public void cancelAllNotifications() {
Log.w(TAG, "cancelAllNotifications not implemented");
}

@UsedByGodot
public void register_remote_notification() {
}

@UsedByGodot
public String get_device_token() {
return "";
}
Expand All @@ -144,7 +146,7 @@ private PendingIntent getPendingIntent(String message, String title, int tag) {
i.putExtra("notification_id", tag);
i.putExtra("message", message);
i.putExtra("title", title);
PendingIntent sender = PendingIntent.getBroadcast(getActivity(), tag, i, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent sender = PendingIntent.getBroadcast(getActivity(), tag, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
return sender;
}

Expand Down Expand Up @@ -193,17 +195,17 @@ private void checkIntent() {
}
intentWasChecked = true;
}

@UsedByGodot
public Dictionary get_notification_data() {
if(!intentWasChecked) checkIntent();
return notificationData;
}

@UsedByGodot
public String get_deeplink_action() {
if(!intentWasChecked) checkIntent();
return action;
}

@UsedByGodot
public String get_deeplink_uri() {
if(!intentWasChecked) checkIntent();
return uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void onReceive(Context context, Intent intent) {

Intent intent2 = new Intent(context, appClass);
intent2.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

int iconID = context.getResources().getIdentifier("icon", "mipmap", context.getPackageName());
int notificationIconID = context.getResources().getIdentifier("notification_icon", "mipmap", context.getPackageName());
Expand Down