Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25864

Android: Notifications should use default channel on Android 8 if not assigned

    Details

      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:

      1. Set up "tiapp.xml" to target API Level 26 as shown below.
      2. Build and run the below code on an Android 8 device.
      3. Tap on the "Send Notification" button.
      4. 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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Joshua Quick
              • Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code