Example usage for android.media AudioManager getRingerMode

List of usage examples for android.media AudioManager getRingerMode

Introduction

In this page you can find the example usage for android.media AudioManager getRingerMode.

Prototype

public int getRingerMode() 

Source Link

Document

Returns the current ringtone mode.

Usage

From source file:Main.java

/**
 * Returns whether the phone is currently in silent mode.
 *///from www.  ja va  2s  . co  m
public static boolean isPhoneSilent(AudioManager audioManager) {
    return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
}

From source file:Main.java

public static boolean isPhoneSilent(AudioManager audioManager) {
    return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
}

From source file:Main.java

public static boolean isSilent(AudioManager mAudioManager) {
    int ringerMode = mAudioManager.getRingerMode();
    return ringerMode == AudioManager.RINGER_MODE_SILENT;
}

From source file:Main.java

public static boolean isRingAndVibrate(AudioManager mAudioManager) {
    int ringerMode = mAudioManager.getRingerMode();
    int vibrateMode = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
    return ringerMode == AudioManager.RINGER_MODE_NORMAL && vibrateMode == AudioManager.VIBRATE_SETTING_ON;
}

From source file:Main.java

public static boolean isRingOnly(AudioManager mAudioManager) {
    int ringerMode = mAudioManager.getRingerMode();
    int vibrateMode = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
    return ringerMode == AudioManager.RINGER_MODE_NORMAL && vibrateMode == AudioManager.VIBRATE_SETTING_OFF;
}

From source file:Main.java

public static int getRingerMode(Context mContext) {
    AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    return am.getRingerMode();
}

From source file:Main.java

public static boolean isRingerEnable(Context context) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    final int audioMode = am.getRingerMode();
    if (audioMode == AudioManager.RINGER_MODE_NORMAL) {
        return true;
    } else {//w  ww  .  j av a  2 s  .c  o  m
        return false;
    }
}

From source file:Main.java

public static void setCurrentRingerMode(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        currentMode = AudioManager.RINGER_MODE_NORMAL;
        currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
        Log.i("Current Mode Normal", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        currentMode = AudioManager.RINGER_MODE_VIBRATE;
        Log.i("Current Mode Vibrate", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
        currentMode = AudioManager.RINGER_MODE_SILENT;
        Log.i("Current Mode Silent", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else {// w w  w  .  ja v  a2  s.c  o  m
        Log.i("Nothing ", "Matched above");
    }

}

From source file:com.kaliturin.blacklist.utils.Notifications.java

private static void notify(Context context, String title, String message, String ticker, @DrawableRes int icon,
        String action, Uri ringtone, boolean vibration) {

    // turn off sound and vibration if phone is in silent mode
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        ringtone = null;//from   w w w . j  av a  2 s  .  c  o  m
        vibration = false;
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        ringtone = null;
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        break;
    }

    // pending intent for activating app on click in status bar
    Intent intent = new Intent(context, MainActivity.class);
    intent.setAction(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    // build notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentIntent(pendingIntent);
    builder.setContentTitle(title);
    builder.setTicker(ticker);
    builder.setContentText(message);
    builder.setSmallIcon(icon);
    builder.setColor(getColor(context, R.attr.colorAccent));
    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    builder.setPriority(PRIORITY_MAX);
    builder.setAutoCancel(true);
    if (ringtone != null) {
        builder.setSound(ringtone);
    }
    if (vibration) {
        builder.setVibrate(new long[] { 0, 300, 300, 300 });
    }
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}

From source file:count.ly.messaging.CrashDetails.java

/**
 * Checks if device is muted.//from ww  w. jav  a  2  s .  c om
 */
static String isMuted(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        return "true";
    case AudioManager.RINGER_MODE_VIBRATE:
        return "true";
    default:
        return "false";
    }
}