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

v0.10.0; multiple Android and iOS fixes #2000

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

fquirin
Copy link

@fquirin fquirin commented Dec 27, 2022

Latest v0.10.0 is a merge of @timkellypa, @bhandaribhumin (with changes by @powowbox) and @fquirin.

Notable changes:

  • Fixed Android 12 bug to make notifications clickable (@powobox) by replacing the action handler services with activities (avoid notification trampoline restrictions)
  • Added missing 'PendingIntent.FLAG_MUTABLE' and fixed gradle
  • Guard against webview crash
  • Add thread identifier property
  • Delete Alarms when intent is deleted
  • Not calling delegate events if nil or if we're consuming the notification
  • Android 13 POST_NOTIFICATIONS permission and runtime popup added
  • New interfaces to ask for / register permissions required to schedule local notifications
  • ... (see CHANGELOG)

src/android/LocalNotification.java Outdated Show resolved Hide resolved
src/android/LocalNotification.java Outdated Show resolved Hide resolved

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Method Options.getChannel is doing, what we need.

Copy link
Author

Choose a reason for hiding this comment

The 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)

*
* @param command The callback context used when calling back into JavaScript.
*/
private void dummyNotifications(CallbackContext command) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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


mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved it inside the if-case

fireEvent("dummyNotifications");
NotificationManager mNotificationManager;
NotificationCompat.Builder mBuilder;
String NOTIFICATION_CHANNEL_ID = "10004457";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this channel-Id? It should be configurable.

Copy link
Author

Choose a reason for hiding this comment

The 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).

@GitToTheHub
Copy link
Collaborator

@fquirin There is a bug in the method "dummyNotifications". It creates a channel "NOTIFICATION_CHANNEL_NAME". The channel name and id is not configurable.

@GitToTheHub
Copy link
Collaborator

@fquirin You could add in the notable changes for "fixed gradle" that "compile" is replaced by "implementation" for the notifications plugin and for the badge-plugin by using a fixed fork.
It would be cool, if you would extend the notable changes by adding "iOS" or "Android". So it's clear, to which platform a change is related.

@GitToTheHub
Copy link
Collaborator

I merged the android 10 updates from @timkellypa and 2 gradle pr's. It seems everything ok for you. I communicated with the author of this plugin, if he can make a new release of cordova-plugin-badge. So if he did this, we can link this pr to the original plugin back.

</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 -->
Copy link
Author

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

@fquirin
Copy link
Author

fquirin commented Mar 19, 2023

I added a comment so we don't forget :-) and resolved the README conflict

@GitToTheHub
Copy link
Collaborator

Very good. Do you know, why we can see still the Android 10 updates from @timkellypa in your pr though i merged them already?

@fquirin
Copy link
Author

fquirin commented Mar 19, 2023

Do you mean the commit from 'Jan 30, 2021'? I think that is just some branch merging, idk, but it seems to show no actual changes 🤔. All the 2020 commits seem to have disappeared (as expected).

@GitToTheHub
Copy link
Collaborator

Yeah i see this, they are disappeared. Very good, I'm happy :)

@dpalou
Copy link
Contributor

dpalou commented Mar 20, 2023

Hi @fquirin ,

I've barely developed Android native code in 8 years, so I'm probably not the best person to ask for advice ^^' That's why I didn't submit a PR to your branch.

Yes, PermissionHelper is org.apache.cordova.PermissionHelper. I saw it used in cordova-plugin-camera. They use hasPermission too, I don't know if it should be used here too or using getNotCompMgr().areNotificationsEnabled() is enough.

I don't know if an Android version check is needed or not, maybe in old versions the hasPermission function always returns true so it isn't needed, I didn't try.

I think that if the user rejects the permission then the requestPermission function will not prompt him again, it will act as if the user denied the permission again. But I cannot guarantee it without some testing.

About onRequestPermissionsResult, the CordovaPlugin class (the one LocalNotification inherits from) already implements this callback and can be overriden. The first parameter passed to requestPermissions should be the class that implements this callback.

I'm currently with another project too, if I have time in the following weeks I can try to perform a few more tests.

Thanks again for your work, and thanks @GitToTheHub too for assuming the maintenance of this plugin :)

Cheers,
Dani

@GitToTheHub
Copy link
Collaborator

Thanks again for your work, and thanks @GitToTheHub too for assuming the maintenance of this plugin :)

Thank you :)

@bartvanvelden
Copy link

Great to see the changes proposed here. What needs to be done to have this finalised?

@GitToTheHub
Copy link
Collaborator

First I need access to cordova-plugin-badge from the author, to make a new release. Then we need the fixes for this pr from the other contributors.

@dpalou
Copy link
Contributor

dpalou commented Apr 13, 2023

Just for the record, this is the code I've ended up using in our fork to request the POST_NOTIFICATIONS runtime permission if needed. Maybe the same can be achieved using the setDummyNotifications method included in this PR, I don't know.

If the permission is already granted or device is Android 12-, nothing will happen. If it isn't, then the user will be asked when:

  • The JS code of the app calls requestPermission.
  • The JS code of the app calls schedule or update with skipPermission != true.

In that case, the user will be able to allow or deny the permission. If it's denied, the next time any of the functions above is called the user will be asked a second time. If it's denied again, then it will be denied forever, the user won't be asked again.

I'm not an Android native developer so I might have done something wrong, the first tests were ok but we still need to do some exhaustive testing about this. Feel free to cherry-pick this commit in the PR if you want :)

@GitToTheHub
Copy link
Collaborator

@fquirin Do you think the code from @dpalou could be helpful for you, to unify the requestPermission thing? I already talked with @katzer and he will release a new release for cordova-plugin-badge the next time.

@fquirin
Copy link
Author

fquirin commented Apr 19, 2023

Do you think the code from @dpalou could be helpful for you, to unify the requestPermission thing?

I think so, the code looks pretty straight forward. Currently I'm more concerned about the issue with click-events and singleTask or respectively the camera and singleInstance (#2000 (comment)). This will require A LOT of testing.

I already talked with @katzer and he will release a new release for cordova-plugin-badge the next time.

Top 👍

@dpalou
Copy link
Contributor

dpalou commented Apr 20, 2023

My previous commit had an error ^^' here's the fix:

moodlemobile@9b5b10d

@GitToTheHub
Copy link
Collaborator

Thank you :)

@GitToTheHub
Copy link
Collaborator

@fquirin katzer finally published a release of cordova-plugin-badge. Could you test if everything is fine with it?

Currently I'm more concerned about the issue with click-events and singleTask or respectively the camera and singleInstance … This will require A LOT of testing.

Do you think it’s so hard to manage? Maybe we could ask @powowbox for help.

@powowbox
Copy link

Hi,
@GitToTheHub
Have a look on this commit bhandaribhumin/cordova-plugin-local-notification-12@bfc4214

@GitToTheHub
Copy link
Collaborator

@powowbox Cool, thank you :)

@fquirin Could you maybe also test the changes recommended by @powowbox? Maybe this fixes the problem.

@fquirin
Copy link
Author

fquirin commented Apr 25, 2023

@fquirin katzer finally published a release of cordova-plugin-badge. Could you test if everything is fine with it?

Nice, I'll try to run some tests as soon as I can :-).

Do you think it’s so hard to manage? Maybe we could ask @powowbox for help.

Well I don't know yet. I think the first step has to be to create a dedicated test app to make sure there is nothing else causing the bugs I see.

Have a look on this commit bhandaribhumin/cordova-plugin-local-notification-12@bfc4214

I commented this change a few weeks ago with the following:

I've tried your changes with my app and as long as I stay on singleInstance it works, but when I switch back to singleTask (I've used this in the old version of my app) I seem to loose notification click-events that are triggered while the app is open 🤔. I get the event when I close the app before. Any idea what might cause this?

If this remains true for a clean test app we need to start digging to find the problem :-|.

@fquirin
Copy link
Author

fquirin commented Apr 25, 2023

I have some good news @GitToTheHub :-). Did a clean build with the original (updated) 'cordova-plugin-badge' dependency and saw no errors so far. In addition it seems my singleInstance to singleTask issue has disappeared as well :-).
I'll try to run more tests and implement the permission fixes on Thursday/Friday maybe.

I found some more Android fixes in a PR to my own fork that look important, but I'd prefer to add them later in a new PR.

@GitToTheHub
Copy link
Collaborator

Hey @fquirin, this sounds very cool. So we can make this plugin working again. Thank you :)

@jayseb11
Copy link

Seems like this issue is fixed - great job! Is there an ETA for when this will merged?

@GitToTheHub
Copy link
Collaborator

We have to wait for the fixes from @fquirin

@fquirin How far did you come with the testing?

@jayseb11
Copy link

jayseb11 commented Jun 3, 2023

@fquirin @GitToTheHub I understand time is scarce and it is difficult to contribute to OS projects. However, I would really appreciate if we can get this plugin working. I am receiving a lot of complaints on my apps due to this plugin issues, so any help to move this forward is appreciated.

I am not very proficient in native code, but if you provide pointers I could contribute as well.

@powowbox
Copy link

powowbox commented Jun 4, 2023

@jayseb11
Hi, if you're in a hurry, use my fork https://github.com/powowbox/cordova-plugin-local-notification-12 . I use it currently in production and it solves the main issues.
When folks will have finish the merge job you could change for the official version.

@fquirin
Copy link
Author

fquirin commented Jun 9, 2023

Hey guys, sorry for the late reply. I'm currently drowning in work, but I'll try to fix this as soon as I can.

@GitToTheHub
Copy link
Collaborator

@fquirin Cool, thank you :)

@@ -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" />

Choose a reason for hiding this comment

The 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)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have do it in a separate PR.
@fquirin What do you think?

@GitToTheHub
Copy link
Collaborator

@fquirin Hi Florian, could you find maybe some time to finish this PR? This would be greate :) Regards Manuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants