Search in sources :

Example 1 with WearableExtender

use of androidx.core.app.NotificationCompat.WearableExtender in project Applozic-Android-SDK by AppLozic.

the class WearableNotificationWithVoice method sendNotification.

/**
 * This method is just like a wrapper class method for usual notification class which add voice actions
 * for wearable devices
 *
 * @throws RuntimeException
 */
// Cleanup: defalut
public void sendNotification() throws Exception {
    if (pendingIntent == null && notificationHandler == null) {
        throw new RuntimeException("Either pendingIntent or handler class requires.");
    }
    // Action action = buildWearableAction(); removed remote input action for now
    Notification notification = notificationBuilder.extend(new WearableExtender()).build();
    if (ApplozicClient.getInstance(mContext).isNotificationSmallIconHidden() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        int smallIconViewId = mContext.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
        if (smallIconViewId != 0) {
            if (notification.contentIntent != null && notification.contentView != null) {
                notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (notification.headsUpContentView != null) {
                    notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
                }
                if (notification.bigContentView != null) {
                    notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
                }
            }
        }
    }
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext);
    notificationManager.notify(notificationId, notification);
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Notification(android.app.Notification) WearableExtender(androidx.core.app.NotificationCompat.WearableExtender)

Aggregations

Notification (android.app.Notification)1 WearableExtender (androidx.core.app.NotificationCompat.WearableExtender)1 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)1