当前位置: 首页>>代码示例>>Java>>正文


Java NotificationManager.INTERRUPTION_FILTER_ALL属性代码示例

本文整理汇总了Java中android.app.NotificationManager.INTERRUPTION_FILTER_ALL属性的典型用法代码示例。如果您正苦于以下问题:Java NotificationManager.INTERRUPTION_FILTER_ALL属性的具体用法?Java NotificationManager.INTERRUPTION_FILTER_ALL怎么用?Java NotificationManager.INTERRUPTION_FILTER_ALL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.NotificationManager的用法示例。


在下文中一共展示了NotificationManager.INTERRUPTION_FILTER_ALL属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMessageReceived

@Override
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived: " + messageEvent);

    switch (messageEvent.getPath()) {
        case PATH_DND:
            if (messageEvent.getData().length == 0)
                return;

            int state = (int) messageEvent.getData()[0];

            Log.d(TAG, "Target state: " + state);

            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                if (state != NotificationManager.INTERRUPTION_FILTER_ALL)
                    state = NotificationManager.INTERRUPTION_FILTER_ALARMS;
                if (state == (int) notificationManager.getCurrentInterruptionFilter())
                    return;

                if (notificationManager.isNotificationPolicyAccessGranted())
                    notificationManager.setInterruptionFilter(state);
            } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Intent intent = new Intent(LGHackService.ACTION_SET_STATE);
                intent.putExtra(LGHackService.EXTRA_STATE, (int) messageEvent.getData()[0]);
                sendBroadcast(intent);
            } else {
                AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
                state = state == 4 ?  AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_NORMAL;
                //INTERRUPTION_FILTER_ALARMS
                if (state == audioManager.getRingerMode())
                    return;
                audioManager.setRingerMode(state);
            }
            return;
        case PATH_DND_REGISTER:
            if (messageEvent.getData().length == 0)
                return;

            Intent connectIntent = new Intent(WEAR_CALLBACK_CONNECT);
            if (messageEvent.getData().length > 1) {
                DataMap config = DataMap.fromByteArray(messageEvent.getData());
                connectIntent.putExtra("permission", config.getBoolean("permission"));
            }
            sendBroadcast(connectIntent);
            Log.d(TAG, "Connected broadcast");
            return;
        case PATH_LOGS:
            if (messageEvent.getData().length == 0)
                return;

            Intent logIntent = new Intent(WEAR_CALLBACK_LOGS);
            logIntent.putExtra("log", new String(messageEvent.getData()));
            sendBroadcast(logIntent);
            Log.d(TAG, "Logs broadcast");
            return;
    }
}
 
开发者ID:rkkr,项目名称:wear-dnd-sync,代码行数:58,代码来源:SettingsService.java


注:本文中的android.app.NotificationManager.INTERRUPTION_FILTER_ALL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。