Example usage for android.media AudioManager RINGER_MODE_SILENT

List of usage examples for android.media AudioManager RINGER_MODE_SILENT

Introduction

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

Prototype

int RINGER_MODE_SILENT

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

Click Source Link

Document

Ringer mode that will be silent and will not vibrate.

Usage

From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java

public void releaseToRefresh() {
    if (!mArrowRotated) {
        mHeaderArrow.startAnimation(mRotateAnimation);
        rotateArrow();//from  w  w w.  j  a v a  2  s. c o m
        mArrowRotated = true;
        if (!hasPlayedSound) {
            hasPlayedSound = true;
            boolean isMuted = false;

            switch (audioManager.getRingerMode()) {
            case AudioManager.RINGER_MODE_NORMAL:
                isMuted = false;
                break;
            case AudioManager.RINGER_MODE_SILENT:
                isMuted = true;
                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                isMuted = true;
                break;
            }
            if (mPreferences.getBoolean(PREFERENCE_KEY_SOUND_NAVIGATION, true)) {
                if (isMuted != true) {
                    if (mPlayer != null) {
                        if (mPlayer.isPlaying()) {
                            mPlayer.stop();
                        }
                        mPlayer.release();
                    }
                    mPlayer = MediaPlayer.create(mContext, R.raw.pulldown);
                    mPlayer.start();
                }
            }
        }
    }
    mHeaderText.setText(Html.fromHtml(mReleaseLabel));
}

From source file:cc.psdev.heywifi.MainService.java

private boolean changeRingmode() {
    for (int i = 0; i < 30; i++) {
        try {//from  w w  w .  j a v  a2s  .  c o m
            for (int j = 0; j < 20; j++) {
                if (ringmode[j] != -1 && resbssid[i].equals(bssid[j])) {

                    if (pref.getSignal() == 1 && ressignal[i] < SIGNAL_MINIMUM) {
                        continue;
                    } else {

                        if (pref.getRingmodeSaved() < 10) {
                            switch (audm.getRingerMode()) {
                            case 2:
                                pref.putRingmodeSaved(12);
                                break;
                            case 1:
                                pref.putRingmodeSaved(11);
                                break;
                            case 0:
                                pref.putRingmodeSaved(10);
                                break;
                            }
                        }

                        switch (ringmode[j]) {
                        case 2:
                            audm.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                            return true;
                        case 1:
                            audm.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                            return true;
                        case 0:
                            audm.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                            return true;
                        }

                    }
                }
            }
        } catch (NullPointerException ex) {
        }
    }

    return false;
}

From source file:net.geniecode.ttr.ScheduleReceiver.java

@SuppressWarnings("deprecation")
@SuppressLint({ "Recycle", "NewApi", "InlinedApi" })
@Override// ww w  .  j a  v a 2 s  . com
public void onReceive(Context context, Intent intent) {
    if (!Schedules.SCHEDULE_ACTION.equals(intent.getAction())) {
        // Unknown intent, bail.
        return;
    }

    Schedule schedule = null;
    // Grab the schedule from the intent. Since the remote AlarmManagerService
    // fills in the Intent to add some extra data, it must unparcel the
    // Schedule object. It throws a ClassNotFoundException when unparcelling.
    // To avoid this, do the marshalling ourselves.
    final byte[] data = intent.getByteArrayExtra(Schedules.SCHEDULE_RAW_DATA);
    if (data != null) {
        Parcel in = Parcel.obtain();
        in.unmarshall(data, 0, data.length);
        in.setDataPosition(0);
        schedule = Schedule.CREATOR.createFromParcel(in);
    }

    if (schedule == null) {
        // Make sure we set the next schedule if needed.
        Schedules.setNextSchedule(context);
        return;
    }

    // Disable this schedule if it does not repeat.
    if (!schedule.daysOfWeek.isRepeatSet()) {
        Schedules.enableSchedule(context, schedule.id, false);
    } else {
        // Enable the next schedule if there is one. The above call to
        // enableSchedule will call setNextSchedule so avoid calling it twice.
        Schedules.setNextSchedule(context);
    }

    long now = System.currentTimeMillis();

    if (now > schedule.time + STALE_WINDOW) {
        return;
    }

    // Get telephony service
    mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    // Execute only for devices with versions of Android less than 4.2
    if (android.os.Build.VERSION.SDK_INT < 17) {
        // Get flight mode state
        boolean isEnabled = Settings.System.getInt(context.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 0) == 1;

        // Get Wi-Fi service
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

        if ((schedule.aponoff) && (!isEnabled) && (schedule.mode.equals("1"))
                && (mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) {
            // Enable flight mode
            Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
                    isEnabled ? 0 : 1);

            // Get Wi-Fi state and disable that one too, just in case
            // (On some devices it doesn't get disabled when the flight mode is
            // turned on, so we do it here)
            boolean isWifiEnabled = mWifiManager.isWifiEnabled();

            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);

            if (isWifiEnabled) {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean(WIFI_STATE, isWifiEnabled);
                editor.commit();
                mWifiManager.setWifiEnabled(false);
            } else {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean(WIFI_STATE, isWifiEnabled);
                editor.commit();
            }

            // Post an intent to reload
            Intent relintent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            relintent.putExtra("state", !isEnabled);
            context.sendBroadcast(relintent);
        } else if ((!schedule.aponoff) && (isEnabled) && (schedule.mode.equals("1"))) {
            // Disable flight mode
            Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
                    isEnabled ? 0 : 1);

            // Restore previously remembered Wi-Fi state
            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
            Boolean WiFiState = settings.getBoolean(WIFI_STATE, true);

            if (WiFiState) {
                mWifiManager.setWifiEnabled(true);
            }

            // Post an intent to reload
            Intent relintent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            relintent.putExtra("state", !isEnabled);
            context.sendBroadcast(relintent);
        }
        // Check whether there are ongoing phone calls, and if so
        // show notification instead of just enabling the flight mode
        else if ((schedule.aponoff) && (!isEnabled) && (schedule.mode.equals("1"))
                && (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)) {
            setNotification(context);
        }
        // Execute for devices with Android 4.2   or higher
    } else {
        // Get flight mode state
        String result = Settings.Global.getString(context.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON);

        if ((schedule.aponoff) && (result.equals("0")) && (schedule.mode.equals("1"))
                && (mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE)) {
            // Keep the device awake while enabling flight mode
            Intent service = new Intent(context, ScheduleIntentService.class);
            startWakefulService(context, service);
        } else if ((!schedule.aponoff) && (result.equals("1")) && (schedule.mode.equals("1"))) {
            // Keep the device awake while enabling flight mode
            Intent service = new Intent(context, ScheduleIntentService.class);
            startWakefulService(context, service);
        } else if ((schedule.aponoff) && (result.equals("0")) && (schedule.mode.equals("1"))
                && (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)) {
            setNotification(context);
        }
    }

    // Get audio service
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    // Get current ringer mode and set silent or normal mode accordingly
    switch (mAudioManager.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        if ((!schedule.silentonoff) && (schedule.mode.equals("2"))) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        if ((schedule.silentonoff) && (schedule.mode.equals("2"))) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        // If the phone is set to vibrate let's make it completely silent
        if ((schedule.silentonoff) && (schedule.mode.equals("2"))) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
        // or restore the regular sounds on it if that's scheduled
        else if ((!schedule.silentonoff) && (schedule.mode.equals("2"))) {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        break;
    }
}

From source file:fr.inria.ucn.collectors.SysStateCollector.java

@SuppressWarnings("deprecation")
private JSONObject getAudioState(Context c) throws JSONException {
    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    JSONObject data = new JSONObject();

    data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn());
    data.put("is_microphone_mute", am.isMicrophoneMute());
    data.put("is_music_active", am.isMusicActive());
    data.put("is_speaker_phone_on", am.isSpeakerphoneOn());
    data.put("is_wired_headset_on", am.isWiredHeadsetOn());

    switch (am.getMode()) {
    case AudioManager.MODE_IN_CALL:
        data.put("mode", "in_call");
        break;/* w ww . jav  a2  s . co  m*/
    case AudioManager.MODE_IN_COMMUNICATION:
        data.put("mode", "in_comm");
        break;
    case AudioManager.MODE_NORMAL:
        data.put("mode", "normal");
        break;
    case AudioManager.MODE_RINGTONE:
        data.put("mode", "ringtone");
        break;
    case AudioManager.MODE_INVALID:
    default:
        data.put("mode", "invalid");
        break;
    }

    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        data.put("ringer_mode", "vibrate");
        break;
    case AudioManager.RINGER_MODE_SILENT:
        data.put("ringer_mode", "silent");
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        data.put("ringer_mode", "normal");
        break;
    default:
        data.put("ringer_mode", "invalid");
        break;
    }
    return data;
}

From source file:cc.psdev.heywifi.MainService.java

private void changeFromSavedRingmode(int ringmode) {
    switch (ringmode) {
    case 2:/*from   w  w  w . j  a  va2s.c o m*/
        audm.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        break;
    case 1:
        audm.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        break;
    case 0:
        audm.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        break;
    }
}

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

/**
 * Checks if device is muted./* w ww  . j a va  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";
    }
}

From source file:net.networksaremadeofstring.rhybudd.Notifications.java

public static void SendPollNotification(int EventCount, List<String> EventDetails, Context context) {
    Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Intent broadcastMassAck = new Intent();
    broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0);

    /*Intent broadcastIgnore = new Intent();
    broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this,0,broadcastIgnore,0);*/

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    Uri soundURI;//from  ww w .j  a  va2  s.  c om
    int Flags = -1;
    String Event1 = "--", Event2 = "---";
    int remainingCount = 0;

    try {
        if (settings.getBoolean("notificationSound", true)) {
            if (settings.getString("notificationSoundChoice", "").equals("")) {
                soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            } else {
                try {
                    soundURI = Uri.parse(settings.getString("notificationSoundChoice", ""));
                } catch (Exception e) {
                    soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            }
        } else {
            soundURI = null;
        }
    } catch (Exception e) {
        soundURI = null;
    }

    try {
        if (EventDetails.size() > 1) {
            Event1 = EventDetails.get(0);
            Event2 = EventDetails.get(1);
            remainingCount = EventCount - 2;
        } else {
            Event1 = EventDetails.get(0);
            remainingCount = EventCount - 1;
        }
    } catch (Exception e) {

    }

    long[] vibrate = { 0, 100, 200, 300 };

    try {
        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

        //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode()));
        switch (audio.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            //Do nothing to fix GitHub issue #13
            //Log.e("AudioManager","Doing nothing because we are silent");
            vibrate = new long[] { 0, 0 };
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat_alert)
                .setContentTitle(Integer.toString(EventCount) + " new Zenoss Events!")
                .setContentText("Tap to start Rhybudd").setContentIntent(contentIntent).setNumber(EventCount)
                .setSound(soundURI).setVibrate(vibrate).setAutoCancel(true).setOngoing(false)
                .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck)
                .setPriority(Notification.PRIORITY_HIGH);

        Notification notif = mBuilder.build();
        notif.tickerText = Integer.toString(EventCount) + " new Zenoss Events!";

        if (settings.getBoolean("notificationSoundInsistent", false))
            notif.flags |= Notification.FLAG_INSISTENT;

        NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNM.notify(NOTIFICATION_POLLED_ALERTS, notif);
    } catch (Exception e) {

    }
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void vibrate(long miliseconds) {
    AudioManager audio = (AudioManager) BackendControllerImpl.getInstance().getFrontend().getContext()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audio.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
        Vibrator v = (Vibrator) BackendControllerImpl.getInstance().getFrontend().getContext()
                .getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(miliseconds);/*from ww w. j  a  va 2  s  .  c o  m*/
    }
}

From source file:com.ferdi2005.secondgram.NotificationsController.java

protected void showSingleBackgroundNotification() {
    notificationsQueue.postRunnable(new Runnable() {
        @Override/*from www  .  j  av a  2  s  .  co  m*/
        public void run() {
            try {
                if (!ApplicationLoader.mainInterfacePaused) {
                    return;
                }
                SharedPreferences preferences = ApplicationLoader.applicationContext
                        .getSharedPreferences("Notifications", Context.MODE_PRIVATE);

                boolean notifyDisabled = false;
                int needVibrate = 0;
                String choosenSoundPath = null;
                int ledColor = 0xff0000ff;
                int priority = 0;
                int vibrateOverride;

                if (!preferences.getBoolean("EnableAll", true)) {
                    notifyDisabled = true;
                }

                String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
                if (!notifyDisabled) {
                    vibrateOverride = 0;
                    choosenSoundPath = null;
                    boolean vibrateOnlyIfSilent = false;

                    if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
                        choosenSoundPath = null;
                    } else if (choosenSoundPath == null) {
                        choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
                    }
                    needVibrate = preferences.getInt("vibrate_messages", 0);
                    priority = preferences.getInt("priority_group", 1);
                    ledColor = preferences.getInt("MessagesLed", 0xff0000ff);

                    if (needVibrate == 4) {
                        vibrateOnlyIfSilent = true;
                        needVibrate = 0;
                    }
                    if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3)
                            || needVibrate != 2 && vibrateOverride == 2
                            || vibrateOverride != 0 && vibrateOverride != 4) {
                        needVibrate = vibrateOverride;
                    }
                    if (vibrateOnlyIfSilent && needVibrate != 2) {
                        try {
                            int mode = audioManager.getRingerMode();
                            if (mode != AudioManager.RINGER_MODE_SILENT
                                    && mode != AudioManager.RINGER_MODE_VIBRATE) {
                                needVibrate = 2;
                            }
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                }

                Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
                intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
                intent.setFlags(32768);

                PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0,
                        intent, PendingIntent.FLAG_ONE_SHOT);

                String name = LocaleController.getString("AppName", R.string.AppName);

                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                        ApplicationLoader.applicationContext).setContentTitle(name)
                                .setSmallIcon(R.drawable.notification).setAutoCancel(true)
                                .setNumber(total_unread_count).setContentIntent(contentIntent)
                                .setGroup("messages").setGroupSummary(true).setColor(0xff2ca5e0);

                mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);

                String lastMessage = LocaleController.getString("YouHaveNewMessage",
                        R.string.YouHaveNewMessage);
                mBuilder.setContentText(lastMessage);
                mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(lastMessage));

                if (priority == 0) {
                    mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
                } else if (priority == 1) {
                    mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
                } else if (priority == 2) {
                    mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
                }

                if (!notifyDisabled) {
                    if (lastMessage.length() > 100) {
                        lastMessage = lastMessage.substring(0, 100).replace('\n', ' ').trim() + "...";
                    }
                    mBuilder.setTicker(lastMessage);
                    if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
                        if (choosenSoundPath.equals(defaultPath)) {
                            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI,
                                    AudioManager.STREAM_NOTIFICATION);
                        } else {
                            mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
                        }
                    }
                    if (ledColor != 0) {
                        mBuilder.setLights(ledColor, 1000, 1000);
                    }
                    if (needVibrate == 2 || MediaController.getInstance().isRecordingAudio()) {
                        mBuilder.setVibrate(new long[] { 0, 0 });
                    } else if (needVibrate == 1) {
                        mBuilder.setVibrate(new long[] { 0, 100, 0, 100 });
                    } else if (needVibrate == 0 || needVibrate == 4) {
                        mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
                    } else if (needVibrate == 3) {
                        mBuilder.setVibrate(new long[] { 0, 1000 });
                    }
                } else {
                    mBuilder.setVibrate(new long[] { 0, 0 });
                }
                notificationManager.notify(1, mBuilder.build());
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    });
}

From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java

private void playRingtone() {
    AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    if ((audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)
            || (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0)) {
        vibrate();/*from w w w.ja va 2  s. c om*/
        delayHandler = new Handler();
        delayHandler.postDelayed(new Runnable() {
            public void run() {
                sendNotificationAndFinish();
            }
        }, MAXIMUM_CALL_NOTIFICATION_DURATION);
    } else if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
        if (mPlayer == null) {
            mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.moments_30s);
            //            mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    sendNotificationAndFinish();
                }
            });
            mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
                    sendNotificationAndFinish();
                    return false;
                }
            });
            mPlayer.start();
        }
    }
}