-
-
Notifications
You must be signed in to change notification settings - Fork 735
Add Notification Channels configuration for Android O #713
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
Add Notification Channels configuration for Android O #713
Conversation
build.gradle
Outdated
@@ -22,11 +22,11 @@ allprojects { | |||
} | |||
|
|||
ext { | |||
compileSdkVersion = 25 | |||
compileSdkVersion = 26 | |||
buildToolsVersion = "25.0.3" |
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.
Should this be changed? Also in travis. I'm not sure, just asking.
What I forgot to mention here is that I only set the channel id for the notification, and then it's up to the user to actually make a channel with that id in their app. |
So I'll leave you my own view on this... Currently I'm not comfortable with the facts that:
I think that:
This way developer can create different channels based on different pushes inside the Intent, with a reasonable default, and also it works out of the box because we create the channel ourselves. Developer also has the chance to customize the What do you guys think? It would be nice to merge this soon since O is rolling out |
I agree with you @natario1. I've tried to modify my code based on your feedback. |
Thanks @iernie ! I like the design, but currently I think this would break for example here. When API < O, you are passing around a null NotificationChannel, but the NotificationChannel does not exist in these platforms. Right? I think you should ensure that any reference to NotificationChannel happens in the NotificationCompat.Builder parseBuilder = new NotificationCompat.Builder(context);
parseBuilder.setContentTitle(title)
.setContentText(alert)
.set ...;
if (androidVersion >= O) {
NotificationChannel channel = getNotificationChannel(); // Not called before O
parseBuilder.setNotificationChannel(channel); // This will use the channel id
} Also this call to |
Then in |
|
What could be done is get NotificationManager and create the channel when you call |
@natario1 I've made some changes. |
NotificationChannel notificationChannel = new NotificationChannel("parse_push", "Push notifications", NotificationManager.IMPORTANCE_DEFAULT); | ||
|
||
// Android doesn't create a new channel if the properties of the channel hasn't changed | ||
nm.createNotificationChannel(notificationChannel); |
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.
Could you move the channel creation outside, maybe in getNotification()
, right after we call getNotificationChannel()
? If someone overrides this method, the creation won't happen
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.
Done
I made the |
@@ -124,6 +128,7 @@ public Notification build(Builder b) { | |||
Bitmap mLargeIcon; | |||
int mPriority; | |||
Style mStyle; | |||
NotificationChannel mNotificationChannel; |
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.
Sorry man, I just noticed this... I am not sure if this might throw at runtime on older APIs, even if not used. Could we just store String mNotificationChannelId
here?
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.
You are right again, this will crash. Sending just the Id is better.
build.gradle
Outdated
@@ -22,11 +22,11 @@ allprojects { | |||
} | |||
|
|||
ext { | |||
compileSdkVersion = 25 | |||
compileSdkVersion = 26 | |||
buildToolsVersion = "25.0.3" |
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.
As before, shouldn't we build with something starting with 26? Here and in travis file... No?
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.
I didn't want to change the build tools since I don't know what the routines are here on that, but I can change to 26.0.1
I could also upgrade the support library to 26.0.1, but then I'd have to raise the minSDK to 14, since they removed support for <14
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.
Looks good to me!
Any insight as to why tests are failing? |
Ahh! |
The last 4 failing tests are because metaData is null for some reason in those tests after upgrading to robolectric 3.4.2. Any pointers on how to solve this are welcome as I am running out of ideas. |
I've tried everything I can think of to get the tests to work with robolectric 3.4.2 and API 26, but I don't feel like I have enough experience with the testing framework or robolectric to get this to work, so any help is appreciated here. Now that Android Oreo is launched, it would be nice to get this merged :) |
No tests were written to test out the Android O based functionality, so I would opt to just keep Robolectric on the version it is on for now. |
The problem is that if the compileSDK isn't 26 then the code fails to compile as NotificationChannel doesn't exist. When compileSDK is 26 then robolectric 3.3 fails because it doesn't support API 26. And with robolectric 3.4.2 I haven't been able to get the last 4 tests running. |
This is not going to fix anything, but you should also update the |
Codecov Report
@@ Coverage Diff @@
## master #713 +/- ##
===========================================
- Coverage 53.06% 53% -0.07%
Complexity 1732 1732
===========================================
Files 132 132
Lines 10254 10266 +12
Branches 1432 1434 +2
===========================================
Hits 5441 5441
- Misses 4364 4376 +12
Partials 449 449
Continue to review full report at Codecov.
|
What... I swear after testing all kinds of combinations of configs and versions, I can't believe that this finally went through. Tests still run on API 25 and robolectric 3.3.2 which is the last 3.3.x version that supports API 26. |
Nice catch. Going to merge, thanks @iernie for bringing up this issue! |
@natario1 Happy to help! :) |
Eventually I think it would be great to move away from testing with Robolectric and just running tests on the emulator. Robolectric causes lots of headaches with how it breaks things. But thanks for suffering through it, @iernie ! |
Haha, yes I think I was on the brink of replacing the whole test framework with something else to get it to work. I found the documentation of Robolectric lacking. There has to be a better way like you said to just test on the emulator. |
@natario1 Just a small thing, but I think you chose the wrong PR in the release notes :) |
You are right, will fix :-) |
Thanks 😄 |
In response to my own issue #711 I tried to add the support myself.
I added the new meta-tag
com.parse.push.notification_channel
which defaults to"parse_push"
.If the Android version SDK is 26 or above, the channelId is set to the notification. The project is also compiled against SDK 26 in order to get the notification api.
I have no idea how to test this, so any help or pointers are appreciated.