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


Java NotificationManager.setInterruptionFilter方法代码示例

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


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

示例1: stopRingtone

import android.app.NotificationManager; //导入方法依赖的package包/类
void stopRingtone(Context context) {
    if (mMediaPlayer != null) {
        mMediaPlayer.reset();
        try {
            AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (am != null) {
                am.setRingerMode(beforeRingerMode);
            } else {
                Log.w("ALARM", "Can't access system service AudioManager");
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                if (mNotificationManager != null) {
                    mNotificationManager.setInterruptionFilter(interruptionFilterBefore);
                } else {
                    Log.w("ALARM", "Can't access system service NotificationManager");
                }
            }
        } catch(SecurityException se) {
            se.printStackTrace();
        }
    }
}
 
开发者ID:dhbw-timetable,项目名称:dhbw-timetable-android,代码行数:24,代码来源:AlarmSupervisor.java

示例2: onMessageReceived

import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
        // Read the received ringer or dnd mode and convert it back to an integer
        int newMode = Integer.parseInt(new String(messageEvent.getData()));

        if (SEND_RINGER_MODE) {
            Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        } else {
            Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        }

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Check if the notification policy access has been granted for the app
        // This is needed to set modes that affect Do Not Disturb in Android N
        if (mNotificationManager.isNotificationPolicyAccessGranted()) {
            if (SEND_RINGER_MODE) {
                Log.d(TAG, "Attempting to set ringer mode " + newMode);

                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                if (newMode == AudioManager.RINGER_MODE_SILENT) {
                    audioManager.setRingerMode(newMode);
                } else {
                    // Set the saved "normal" value
                    audioManager.setRingerMode(getNormalRingerMode());
                }
            } else {
                Log.d(TAG, "Attempting to set dnd mode " + newMode);

                mNotificationManager.setInterruptionFilter(newMode);
            }
        } else {
            Log.d(TAG, "App is not allowed to change Do Not Disturb mode without applying workaround");
        }
    } else {
        super.onMessageReceived(messageEvent);
    }
}
 
开发者ID:blunden,项目名称:DoNotDisturbSync,代码行数:41,代码来源:WearMessageListenerService.java

示例3: playRingtone

import android.app.NotificationManager; //导入方法依赖的package包/类
void playRingtone(Context context) {
    if (mMediaPlayer == null) {
        initialize();
    }
    if (!mMediaPlayer.isPlaying() && !mMediaPlayer.isLooping()) {
        try {
            Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
            mMediaPlayer.setDataSource(context, sound);
            final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (audioManager != null) {
                beforeRingerMode = audioManager.getRingerMode();
                try {
                    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                } catch(SecurityException se) {
                    se.printStackTrace();
                }
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                    if (mNotificationManager != null) {
                        interruptionFilterBefore = mNotificationManager.getCurrentInterruptionFilter();
                        mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL);
                    } else {
                        Log.w("ALARM", "Can't access system service NotificationManager");
                    }
                }
                if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) > 0) {
                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                    mMediaPlayer.prepare();
                    mMediaPlayer.start();
                }
            }
        } catch (IOException | IllegalStateException e) {
            e.printStackTrace();
            mMediaPlayer.reset();
        }
    }
}
 
开发者ID:dhbw-timetable,项目名称:dhbw-timetable-android,代码行数:38,代码来源:AlarmSupervisor.java

示例4: onMessageReceived

import android.app.NotificationManager; //导入方法依赖的package包/类
@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,代码行数:59,代码来源:SettingsService.java

示例5: onMessageReceived

import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
        // Read the received ringer or dnd mode and convert it back to an integer
        int newMode = Integer.parseInt(new String(messageEvent.getData()));

        if (SEND_RINGER_MODE) {
            Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        } else {
            Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        }

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Check if the notification policy access has been granted for the app
        // This is needed to set modes that affect Do Not Disturb in Android N
        if (mNotificationManager.isNotificationPolicyAccessGranted() || Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            if (SEND_RINGER_MODE) {
                Log.d(TAG, "Attempting to set ringer mode " + newMode);

                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                if (newMode == AudioManager.RINGER_MODE_SILENT) {
                    audioManager.setRingerMode(newMode);
                } else {
                    // Set the saved "normal" value
                    audioManager.setRingerMode(getNormalRingerMode());
                }
            } else {
                Log.d(TAG, "Attempting to set dnd mode " + newMode);

                mNotificationManager.setInterruptionFilter(newMode);
            }
        } else {
            Log.i(TAG, "Unable to set new ringer mode due to lack of permissions on device");
            Log.i(TAG, "Launching permissions settings activity on the device");
            Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    } else {
        super.onMessageReceived(messageEvent);
    }
}
 
开发者ID:blunden,项目名称:DoNotDisturbSync,代码行数:45,代码来源:WearMessageListenerService.java


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