Example usage for android.media AudioManager RINGER_MODE_NORMAL

List of usage examples for android.media AudioManager RINGER_MODE_NORMAL

Introduction

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

Prototype

int RINGER_MODE_NORMAL

To view the source code for android.media AudioManager RINGER_MODE_NORMAL.

Click Source Link

Document

Ringer mode that may be audible and may vibrate.

Usage

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected Pair<Boolean, Boolean> soundAndVibrate(Context context, PreferencesHolder preferences) {
    switch (preferences.silentNotification) {
    case ALWAYS: { // Toujours silencieux (pas de son, pas de vibration)
        Pair<Boolean, Boolean> result = Pair.of(false, false);
        return result;
    }/* w w  w . j  ava  2s. c  o m*/
    case NEVER: { // Jamais silencieux (son + vibration)
        Pair<Boolean, Boolean> result = Pair.of(true, true);
        return result;
    }
    case BY_NIGHT: { // Ni son, ni vibration entre 23h et 7h
        Calendar now = Calendar.getInstance();
        int hour = now.get(Calendar.HOUR_OF_DAY);
        boolean soundAndVibrate = hour >= 7 && hour < 23;
        Pair<Boolean, Boolean> result = Pair.of(soundAndVibrate, soundAndVibrate);
        return result;
    }
    case WHEN_SILENT: { // Dpend du systme
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int ringerMode = am.getRingerMode();
        Pair<Boolean, Boolean> result = Pair.of(ringerMode == AudioManager.RINGER_MODE_NORMAL, // son
                ringerMode == AudioManager.RINGER_MODE_NORMAL || ringerMode == AudioManager.RINGER_MODE_VIBRATE // vibration
        );
        return result;
    }
    default:
        Log.w(TAG, "Unexpected mode : " + preferences.silentNotification);
        throw new IllegalStateException("Unexpected mode : " + preferences.silentNotification);
    }
}

From source file:edu.cmu.mpcs.dashboard.TagViewer.java

private String ringerSetting(String settingString) {
    /*****/*from  w  ww.  j av  a2  s  . c o  m*/
     * Setting the phone on Silent, Vibrate and Normal modes
     *****/

    if (settingString.contains("ringer")) {
        AudioManager audMangr;
        audMangr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

        // For Normal mode
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        // For Silent mode
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        // For vibrate
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

        if (settingString.contains("ringer:Loud")) {
            audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            return ("Phone Ringer:Loud\n");

        } else {
            audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            return ("Phone Ringer:Vibrate\n");

        }

        /* Adjusting volume */
        // if (audMangr.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)
        // {
        // Log.d("RINGER", "setting ringer to silent");
        // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        // audMangr.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        //
        // } else {
        // Log.d("RINGER", "setting ringer to normal");
        //
        //
        // }
    }

    return ("");

}

From source file:com.ferdi2005.secondgram.voip.VoIPService.java

private void startRinging() {
    FileLog.d("starting ringing for call " + call.id);
    dispatchStateChanged(STATE_WAITING_INCOMING);
    //ringtone=RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
    //ringtone.play();
    SharedPreferences prefs = getSharedPreferences("Notifications", MODE_PRIVATE);
    ringtonePlayer = new MediaPlayer();
    ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override/*from   w  w w  .  j a  v a2s.  c om*/
        public void onPrepared(MediaPlayer mediaPlayer) {
            ringtonePlayer.start();
        }
    });
    ringtonePlayer.setLooping(true);
    ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
    try {
        String notificationUri;
        if (prefs.getBoolean("custom_" + user.id, false))
            notificationUri = prefs.getString("ringtone_path_" + user.id,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
        else
            notificationUri = prefs.getString("CallsRingtonePath",
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
        ringtonePlayer.setDataSource(this, Uri.parse(notificationUri));
        ringtonePlayer.prepareAsync();
    } catch (Exception e) {
        FileLog.e(e);
        if (ringtonePlayer != null) {
            ringtonePlayer.release();
            ringtonePlayer = null;
        }
    }
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    int vibrate;
    if (prefs.getBoolean("custom_" + user.id, false))
        vibrate = prefs.getInt("calls_vibrate_" + user.id, 0);
    else
        vibrate = prefs.getInt("vibrate_calls", 0);
    if ((vibrate != 2 && vibrate != 4
            && (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE
                    || am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL))
            || (vibrate == 4 && am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)) {
        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        long duration = 700;
        if (vibrate == 1)
            duration /= 2;
        else if (vibrate == 3)
            duration *= 2;
        vibrator.vibrate(new long[] { 0, duration, 500 }, 0);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && !((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()
            && NotificationManagerCompat.from(this).areNotificationsEnabled()) {
        showIncomingNotification();
        FileLog.d("Showing incoming call notification");
    } else {
        FileLog.d("Starting incall activity for incoming call");
        try {
            PendingIntent.getActivity(VoIPService.this, 12345,
                    new Intent(VoIPService.this, VoIPActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0)
                    .send();
        } catch (Exception x) {
            FileLog.e("Error starting incall activity", x);
        }
    }

}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static private void executeBuiltinActionPrimitive(TaskManagerParms taskMgrParms,
        EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar,
        String bia, String dlg_id, String en, String tn) {
    if (bia.equals(BUILTIN_ACTION_WIFI_ON)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_ON);
        setWifiOn(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_OFF)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_OFF);
        setWifiOff(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID);
        setWifiDisableSsid(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID);
        setWifiRemoveSsid(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_ON)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_ON);
        setBluetoothOn(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_OFF)) {
        taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_OFF);
        setBluetoothOff(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_WAIT_1_SEC)) {
        waitTimeTc(taskResponse, 1 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }/*  ww  w.j  a va  2s .c o m*/
    } else if (bia.equals(BUILTIN_ACTION_WAIT_5_SEC)) {
        waitTimeTc(taskResponse, 5 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_WAIT_1_MIN)) {
        waitTimeTc(taskResponse, 1 * 60 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_WAIT_5_MIN)) {
        waitTimeTc(taskResponse, 5 * 60 * 1000);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
    } else if (bia.equals(BUILTIN_ACTION_SWITCH_TO_HOME)) {
        setScreenSwitchToHome(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_LOCK)) {
        setScreenLocked(taskMgrParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON)) {
        screenOnSync(taskMgrParms, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON_ASYNC)) {
        screenOnAsync(taskMgrParms, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_ALARM)) {
        playBackDefaultAlarm(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_NOTIFICATION)) {
        playBackDefaultNotification(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_RINGTONE)) {
        playBackDefaultRingtone(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_VIBRATE)) {
        vibrateDefaultPattern(taskMgrParms.context, ar);
    } else if (bia.equals(BUILTIN_ACTION_RESTART_SCHEDULER)) {
        sendCmdToService(taskResponse, BUILTIN_ACTION_RESTART_SCHEDULER, dlg_id,
                CMD_THREAD_TO_SVC_RESTART_SCHEDULER, BUILTIN_ACTION_RESTART_SCHEDULER);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_NORMAL)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, false);
        //         am.setStreamMute(AudioManager.STREAM_RING, false);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, false);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, false);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_SILENT)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, true);
        //         am.setStreamMute(AudioManager.STREAM_RING, true);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, true);
    } else if (bia.equals(BUILTIN_ACTION_RINGER_VIBRATE)) {
        AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE);
        am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        //         am.setStreamMute(AudioManager.STREAM_MUSIC, true);
        //         am.setStreamMute(AudioManager.STREAM_RING, true);
        //         am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        //           am.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        //           am.setStreamMute(AudioManager.STREAM_ALARM, true);
    } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_ENABLED)) {
        setAutoSyncEnabled(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_DISABLED)) {
        setAutoSyncDisabled(taskMgrParms, envParms, util, taskResponse, ar);
    } else if (bia.equals(BUILTIN_ACTION_ABORT)) {
        ar.action_resp = ActionResponse.ACTION_ABORT;
        ar.resp_msg_text = "Task was aborted";
    } else {
        ar.action_resp = ActionResponse.ACTION_ERROR;
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia);
    }
}

From source file:org.cryptsecure.Utility.java

/**
 * Check if is phone completely muted (even no vibration).
 * //  w w w . j  a va  2 s . c  o  m
 * @param context
 *            the context
 * @return true, if is phone muted
 */
public static boolean isPhoneMuted(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_NORMAL:
        return false;
    case AudioManager.RINGER_MODE_SILENT:
        return true;
    case AudioManager.RINGER_MODE_VIBRATE:
        return false;
    }
    return false;
}

From source file:org.cryptsecure.Utility.java

/**
 * Check if is phone muted but vibration may still be on.
 * /*from ww  w  .  j  a  v a  2  s.c  o m*/
 * @param context
 *            the context
 * @return true, if is phone muted with vibration
 */
public static boolean isPhoneMutedOrVibration(Context context) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_NORMAL:
        return false;
    case AudioManager.RINGER_MODE_SILENT:
        return false;
    case AudioManager.RINGER_MODE_VIBRATE:
        return true;
    }
    return false;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a system notification.//from   ww  w.j a  v  a 2s  .  co  m
 *    
 * @param context            Context.
 * @param notSound            Enable or disable the sound
 * @param notSoundRawId         Custom raw sound id. If enabled and not set 
 *                         default notification sound will be used. Set to -1 to 
 *                         default system notification.
 * @param multipleNot         Setting to True allows showing multiple notifications.
 * @param groupMultipleNotKey   If is set, multiple notifications can be grupped by this key.
 * @param notAction            Action for this notification
 * @param notTitle            Title
 * @param notMessage         Message
 * @param notClazz            Class to be executed
 * @param extras            Extra information
 * 
 */
public static void notification_generate(Context context, boolean notSound, int notSoundRawId,
        boolean multipleNot, String groupMultipleNotKey, String notAction, String notTitle, String notMessage,
        Class<?> notClazz, Bundle extras, boolean wakeUp) {

    try {
        int iconResId = notification_getApplicationIcon(context);
        long when = System.currentTimeMillis();

        Notification notification = new Notification(iconResId, notMessage, when);

        // Hide the notification after its selected
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        if (notSound) {
            if (notSoundRawId > 0) {
                try {
                    notification.sound = Uri.parse("android.resource://"
                            + context.getApplicationContext().getPackageName() + "/" + notSoundRawId);
                } catch (Exception e) {
                    if (LOG_ENABLE) {
                        Log.w(TAG, "Custom sound " + notSoundRawId + "could not be found. Using default.");
                    }
                    notification.defaults |= Notification.DEFAULT_SOUND;
                    notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            } else {
                notification.defaults |= Notification.DEFAULT_SOUND;
                notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            }
        }

        Intent notificationIntent = new Intent(context, notClazz);
        notificationIntent.setAction(notClazz.getName() + "." + notAction);
        if (extras != null) {
            notificationIntent.putExtras(extras);
        }

        //Set intent so it does not start a new activity
        //
        //Notes:
        //   - The flag FLAG_ACTIVITY_SINGLE_TOP makes that only one instance of the activity exists(each time the
        //      activity is summoned no onCreate() method is called instead, onNewIntent() is called.
        //  - If we use FLAG_ACTIVITY_CLEAR_TOP it will make that the last "snapshot"/TOP of the activity it will 
        //     be this called this intent. We do not want this because the HOME button will call this "snapshot". 
        //     To avoid this behaviour we use FLAG_ACTIVITY_BROUGHT_TO_FRONT that simply takes to foreground the 
        //     activity.
        //
        //See http://developer.android.com/reference/android/content/Intent.html           
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        int REQUEST_UNIQUE_ID = 0;
        if (multipleNot) {
            if (groupMultipleNotKey != null && groupMultipleNotKey.length() > 0) {
                REQUEST_UNIQUE_ID = groupMultipleNotKey.hashCode();
            } else {
                if (random == null) {
                    random = new Random();
                }
                REQUEST_UNIQUE_ID = random.nextInt();
            }
            PendingIntent.getActivity(context, REQUEST_UNIQUE_ID, notificationIntent,
                    PendingIntent.FLAG_ONE_SHOT);
        }

        notification.setLatestEventInfo(context, notTitle, notMessage, intent);

        //This makes the device to wake-up is is idle with the screen off.
        if (wakeUp) {
            powersaving_wakeUp(context);
        }

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        //We check if the sound is disabled to enable just for a moment
        AudioManager amanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int previousAudioMode = amanager.getRingerMode();
        ;
        if (notSound && previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }

        notificationManager.notify(REQUEST_UNIQUE_ID, notification);

        //We restore the sound setting
        if (previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            //We wait a little so sound is played
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
            }
        }
        amanager.setRingerMode(previousAudioMode);

        Log.d(TAG, "Android Notification created.");

    } catch (Exception e) {
        if (LOG_ENABLE)
            Log.e(TAG, "The notification could not be created (" + e.getMessage() + ")", e);
    }
}

From source file:com.android.messaging.datamodel.BugleNotifications.java

/**
 * Play the observable conversation notification sound (it's the regular notification sound, but
 * played at half-volume)/*from ww  w . ja v a2  s  .c  o m*/
 */
private static void playObservableConversationNotificationSound(final Uri ringtoneUri) {
    final Context context = Factory.get().getApplicationContext();
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    final boolean silenced = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
    if (silenced) {
        return;
    }

    final NotificationPlayer player = new NotificationPlayer(LogUtil.BUGLE_TAG);
    player.play(ringtoneUri, false, AudioManager.STREAM_NOTIFICATION,
            OBSERVABLE_CONVERSATION_NOTIFICATION_VOLUME);

    // Stop the sound after five seconds to handle continuous ringtones
    ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() {
        @Override
        public void run() {
            player.stop();
        }
    }, 5000);
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean isRingerModeNormal(EnvironmentParms env_parms) {
    boolean result = false;
    if (env_parms.currentRingerMode == AudioManager.RINGER_MODE_NORMAL)
        result = true;/*from  w ww  .  j ava 2s  .c o  m*/
    return result;
}

From source file:com.android.launcher3.Utilities.java

public static void modeNormal(Activity activity) {
    checkPermissionForRingtone(activity);
    AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    if (isModeNormal) {
        mobilemode.setRingerMode(mobileModeNormalPrevious);
        isModeNormal = false;/*from w  ww .  ja  v a2  s  . c  om*/
    } else {
        isModeNormal = true;
        mobileModeNormalPrevious = mobilemode.getRingerMode();
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }
}