Example usage for android.app Notification getChannelId

List of usage examples for android.app Notification getChannelId

Introduction

In this page you can find the example usage for android.app Notification getChannelId.

Prototype

public String getChannelId() 

Source Link

Document

Returns the id of the channel this notification posts to.

Usage

From source file:ti.modules.titanium.android.notificationmanager.NotificationManagerModule.java

@Kroll.method
public void notify(int id, Object notificationValue) {
    NotificationProxy notificationProxy = NotificationProxy.fromObject(notificationValue);
    NotificationManager manager = getManager();
    if (manager != null && notificationProxy != null) {
        // targeting Android O or above? create default channel

        try {/*from  w ww  . j  a  va2  s . c  om*/
            notificationProxy.setCurrentId(id);
            Notification notification = notificationProxy.getNotification();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                    && notification.getChannelId() == DEFAULT_CHANNEL_ID) {
                useDefaultChannel();
            }
            getManager().notify(id, notification);
            HashMap wakeParams = notificationProxy.getWakeParams();
            if (wakeParams != null) {
                int wakeTime = TiConvert.toInt(wakeParams.get("time"), 3000);
                int wakeFlags = TiConvert.toInt(wakeParams.get("flags"), (PowerManager.FULL_WAKE_LOCK
                        | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE));
                PowerManager pm = (PowerManager) TiApplication.getInstance()
                        .getSystemService(TiApplication.getInstance().getApplicationContext().POWER_SERVICE);
                if (pm != null && !pm.isScreenOn()) {
                    try {
                        WakeLock wl = pm.newWakeLock(wakeFlags, "TiWakeLock");
                        wl.acquire(wakeTime);
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
            }
        } catch (Exception e) {

        }
    }
}