[TIMOB-25864] Android: Notifications should use default channel on Android 8 if not assigned
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-06-05T00:14:51.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.3.0 |
Components | Android |
Labels | android, notification |
Reporter | Joshua Quick |
Assignee | Gary Mathews |
Created | 2018-03-13T21:03:36.000+0000 |
Updated | 2018-06-26T22:00:49.000+0000 |
Description
*Summary:*
If an Android app targets API Level 26 or higher, notifications will fail to be posted to the status bar on Android 8.0 or higher unless they're assigned a notification channel as documented here...
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.NotificationChannel
We should modify notifications to auto-assign them the default notification channel if a channel was not already assigned by the developer. This way, when we modify Titanium to auto-target API Level 26 in the future (see ticket: [TIMOB-25852]), notifications will still work. Avoids a breaking change.
Note that if the app targets API Level 25 or lower, Android 8 will auto-assign the notification the default channel for us.
*Test:*
Set up "tiapp.xml" to target API Level 26 as shown below.
Build and run the below code on an Android 8 device.
Tap on the "Send Notification" button.
Verify that the notification was posted to the status bar.
<ti:app>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
</manifest>
</android>
</ti:app>
var notificationId = 0;
var window = Ti.UI.createWindow();
var button = Ti.UI.createButton({ title: "Send Notification" });
button.addEventListener("click", function(e) {
var notification = Ti.Android.createNotification(
{
contentTitle: "Content Title",
contentText: "Content Text",
contentIntent: Ti.Android.createPendingIntent(
{
intent: Ti.Android.createIntent({}),
}),
});
notificationId++;
Ti.Android.NotificationManager.notify(notificationId, notification);
});
window.add(button);
window.open();
*Recommended Solution:*
This should be implemented similar to the following "aps_sdk" library's PR here...
https://github.com/appcelerator/aps_sdk/pull/307
*Note:*
This is not an issue with our "ti.cloudpush" module. It already assigns a default channel to the received push notification.
master: https://github.com/appcelerator/titanium_mobile/pull/9945
Found issue commented in the PR.
FR Passed. PR Merged.
Verified the fix in SDK 7.3.0.v20180626064422. Closing.