Java Code Examples for android.media.AudioManager#RINGER_MODE_VIBRATE

The following examples show how to use android.media.AudioManager#RINGER_MODE_VIBRATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivity.java    From meshenger-android with GNU General Public License v3.0 6 votes vote down vote up
private void startRinging() {
    log("startRinging");
    int ringerMode = ((AudioManager) getSystemService(AUDIO_SERVICE)).getRingerMode();

    if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
        return;
    }

    vibrator = ((Vibrator) getSystemService(VIBRATOR_SERVICE));
    long[] pattern = {1500, 800, 800, 800};
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        VibrationEffect vibe = VibrationEffect.createWaveform(pattern, 0);
        vibrator.vibrate(vibe);
    } else {
        vibrator.vibrate(pattern, 0);
    }

    if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
        return;
    }

    ringtone = RingtoneManager.getRingtone(this, RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE));
    ringtone.play();
}
 
Example 2
Source File: RingerModeSkillViewFragment.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void _fill(@ValidData @NonNull RingerModeConditionData data) {
    switch (data.ringerMode) {
        case AudioManager.RINGER_MODE_VIBRATE:
            rg_ringer_mode.check(R.id.rb_ringer_mode_vibrate);
            break;
        case AudioManager.RINGER_MODE_NORMAL:
            rg_ringer_mode.check(R.id.rb_ringer_mode_normal);
            break;
        default:
            rg_ringer_mode.check(R.id.rb_ringer_mode_silent);
    }
    if (data.ringerMode == AudioManager.RINGER_MODE_NORMAL) {
        switch (data.compareMode) {
            case RingerModeConditionData.COMPARE_MODE_HIGHER_OR_EQUAL:
                rg_volume_match_type.check(R.id.rb_volume_match_above);
                break;
            case RingerModeConditionData.COMPARE_MODE_EQUALS:
                rg_volume_match_type.check(R.id.rb_volume_match_equals);
                break;
            default:
                rg_volume_match_type.check(R.id.rb_volume_match_below);
        }
        sb_volume_match_value.setProgress(data.ringerLevel);
    }
}
 
Example 3
Source File: DialPadView.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
private void triggerFeedBack(int tone, int durationMs)
{
    if (!mIsFeedBackEnable)
        return;

    // 判断系统设置
    AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
    if ((ringerMode == AudioManager.RINGER_MODE_SILENT))
    {
        if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
            vibrate();
        return;
    }
    //震动
    vibrate();
    //发音
    synchronized (mToneGeneratorLock)
    {
        if (mToneGenerator == null)
            return;
        mToneGenerator.startTone(tone, durationMs);
    }
}
 
Example 4
Source File: ScanFeedbackManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 执行扫描反馈
 */
public void performScanFeedback() {
    if (isAudio && isVibrator) {
        playSoundEffect();
        playVibrateEffect();
    } else if (isAudio) {
        playSoundEffect();
    } else if (isVibrator) {
        playVibrateEffect();
    } else {
        switch (audioManager.getRingerMode()) {
            case AudioManager.RINGER_MODE_SILENT:
                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                playVibrateEffect();
                break;
            case AudioManager.RINGER_MODE_NORMAL:
                if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) {
                    playSoundEffect();
                }
                playVibrateEffect();
                break;
        }
    }
}
 
Example 5
Source File: iOSVolumePanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
protected void toggleSilent(int visibility) {
    switch (visibility) {
        case View.VISIBLE:
            int descRes = R.string.silent_c;
            if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) descRes = R.string.vibrate_c;
            if (mMusicActive) descRes = R.string.mute_c;
            silent.setText(descRes);
            silent.setVisibility(View.VISIBLE);
            seekBar.setVisibility(View.GONE);
            break;
        case View.GONE:
            silent.setVisibility(View.GONE);
            seekBar.setVisibility(View.VISIBLE);
            break;
    }
}
 
Example 6
Source File: RingerModeConditionData.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
public boolean match(int ringerMode, int ringerLevel) {
    if (ringerMode == this.ringerMode) {
        if (ringerMode == AudioManager.RINGER_MODE_SILENT || ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
            return true;
        } else {
            switch (compareMode) {
                case COMPARE_MODE_LOWER_OR_EQUAL:
                    return ringerLevel <= this.ringerLevel;
                case COMPARE_MODE_HIGHER_OR_EQUAL:
                    return ringerLevel >= this.ringerLevel;
                case COMPARE_MODE_EQUALS:
                    return ringerLevel == this.ringerLevel;
            }
        }
    }
    return false;

}
 
Example 7
Source File: RtcActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
private void playAudio() {
        switch (audioManager.getRingMode()) {
            case AudioManager.RINGER_MODE_NORMAL://响铃
            case AudioManager.MODE_IN_COMMUNICATION://音频通话
                MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
                if(!isCaller) {
                    audioManager.changeToEarpieceMode();
                } else {
                    audioManager.changeToSpeakerMode();
                }
//                        MediaUtils.loadRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
//                        MediaUtils.playRtcTone(RtcActivity.this);
                break;
            case AudioManager.RINGER_MODE_SILENT://静音
            case AudioManager.RINGER_MODE_VIBRATE://震动
                if(!isCaller) {
                    MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt);
                    audioManager.changeToEarpieceMode();
                } else {
                    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
                    //按照指定的模式去震动。
//				vibrator.vibrate(1000);
                    //数组参数意义:第一个参数为等待指定时间后开始震动,震动时间为第二个参数。后边的参数依次为等待震动和震动的时间
                    //第二个参数为重复次数,-1为不重复,0为一直震动
                    vibrator.vibrate( new long[]{1000,1000},0);
                }
                break;
        }
    }
 
Example 8
Source File: PPNotificationListenerService.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private static int getZenMode(Context context, AudioManager audioManager) {
    // convert to profile zenMode
    int zenMode = 0;
    int systemZenMode = ActivateProfileHelper.getSystemZenMode(context/*, -1*/);
    //PPApplication.logE("PPNotificationListenerService.getZenMode", "systemZenMode=" + systemZenMode);
    int ringerMode = audioManager.getRingerMode();
    switch (systemZenMode) {
        case ActivateProfileHelper.ZENMODE_ALL:
            //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, true))
            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                zenMode = 4;
            else
                zenMode = 1;
            break;
        case ActivateProfileHelper.ZENMODE_PRIORITY:
            //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, true))
            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                zenMode = 5;
            else
                zenMode = 2;
            break;
        case ActivateProfileHelper.ZENMODE_NONE:
            zenMode = 3;
            break;
        case ActivateProfileHelper.ZENMODE_ALARMS: // new filter - Alarm only - Android M
            zenMode = 6;
            break;
    }
    //PPApplication.logE("PPNotificationListenerService.getZenMode", "zenMode=" + zenMode);
    return zenMode;
}
 
Example 9
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private boolean isLoudPhone(Context ctx) {
    AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            return false;
        case AudioManager.RINGER_MODE_VIBRATE:
            return false;
        case AudioManager.RINGER_MODE_NORMAL:
            return true;
    }
    // unknown mode, not sure let's play just in any case.
    return true;
}
 
Example 10
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
public void blinkScreenAndShutterSound(){
    AudioManager audio = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE);
    switch( audio.getRingerMode() ){
        case AudioManager.RINGER_MODE_NORMAL:
            MediaActionSound sound = new MediaActionSound();
            sound.play(MediaActionSound.SHUTTER_CLICK);
            break;
        case AudioManager.RINGER_MODE_SILENT:
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            break;
    }
}
 
Example 11
Source File: SilentOffAction.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
@Override
public String execute(Context context) {
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
    int old_mode = PreferencesUtil.getSilentModeProfile(context);
    if (ringerMode != AudioManager.RINGER_MODE_VIBRATE) {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }
    return super.execute(context);
}
 
Example 12
Source File: AlertPlayer.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private boolean isLoudPhone(Context ctx) {
    AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            return false;
        case AudioManager.RINGER_MODE_VIBRATE:
            return false;
        case AudioManager.RINGER_MODE_NORMAL:
            return true;
    }
    // unknown mode, not sure let's play just in any case.
    return true;
}
 
Example 13
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private boolean isLoudPhone(Context ctx) {
    AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            return false;
        case AudioManager.RINGER_MODE_VIBRATE:
            return false;
        case AudioManager.RINGER_MODE_NORMAL:
            return true;
    }
    // unknown mode, not sure let's play just in any case.
    return true;
}
 
Example 14
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int onSetRingerModeExternal(int ringerModeOld, int ringerModeNew, String caller,
        int ringerModeInternal, VolumePolicy policy) {
    int ringerModeInternalOut = ringerModeNew;
    final boolean isChange = ringerModeOld != ringerModeNew;
    final boolean isVibrate = ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE;

    int newZen = -1;
    switch (ringerModeNew) {
        case AudioManager.RINGER_MODE_SILENT:
            if (isChange) {
                if (mZenMode == Global.ZEN_MODE_OFF) {
                    newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
                }
                ringerModeInternalOut = isVibrate ? AudioManager.RINGER_MODE_VIBRATE
                        : AudioManager.RINGER_MODE_SILENT;
            } else {
                ringerModeInternalOut = ringerModeInternal;
            }
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
        case AudioManager.RINGER_MODE_NORMAL:
            if (mZenMode != Global.ZEN_MODE_OFF) {
                newZen = Global.ZEN_MODE_OFF;
            }
            break;
    }
    if (newZen != -1) {
        setManualZenMode(newZen, null, "ringerModeExternal", caller,
                false /*setRingerMode*/);
    }

    ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller,
            ringerModeInternal, ringerModeInternalOut);
    return ringerModeInternalOut;
}
 
Example 15
Source File: ZenLog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String ringerModeToString(int ringerMode) {
    switch (ringerMode) {
        case AudioManager.RINGER_MODE_SILENT: return "silent";
        case AudioManager.RINGER_MODE_VIBRATE: return "vibrate";
        case AudioManager.RINGER_MODE_NORMAL: return "normal";
        default: return "unknown";
    }
}
 
Example 16
Source File: RingerModeConditionData.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"SimplifiableIfStatement", "RedundantIfStatement"})
@Override
public boolean isValid() {
    if (ringerMode == AudioManager.RINGER_MODE_SILENT || ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
        return true;
    }
    if (ringerMode == AudioManager.RINGER_MODE_NORMAL &&
            (compareMode == COMPARE_MODE_LOWER_OR_EQUAL ||
             compareMode == COMPARE_MODE_HIGHER_OR_EQUAL ||
             compareMode == COMPARE_MODE_EQUALS)) {
        return true;
    }
    return false;
}
 
Example 17
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected void startRingtoneAndVibration(int chatID){
	SharedPreferences prefs = MessagesController.getNotificationsSettings(currentAccount);
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	boolean needRing=am.getRingerMode()!=AudioManager.RINGER_MODE_SILENT;
	if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
		try{
			int mode=Settings.Global.getInt(getContentResolver(), "zen_mode");
			if(needRing)
				needRing=mode==0;
		}catch(Exception ignore){}
	}
	if(needRing){
		if(!USE_CONNECTION_SERVICE){
			am.requestAudioFocus(this, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN);
		}
		ringtonePlayer=new MediaPlayer();
		ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
			@Override
			public void onPrepared(MediaPlayer mediaPlayer){
				ringtonePlayer.start();
			}
		});
		ringtonePlayer.setLooping(true);
		ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
		try{
			String notificationUri;
			if(prefs.getBoolean("custom_"+chatID, false))
				notificationUri=prefs.getString("ringtone_path_"+chatID, 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;
			}
		}
		int vibrate;
		if(prefs.getBoolean("custom_"+chatID, false))
			vibrate=prefs.getInt("calls_vibrate_"+chatID, 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);
		}
	}
}
 
Example 18
Source File: Ringer.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Starts the ringtone and/or vibrator. 
 * 
 */
public void ring(String remoteContact, String defaultRingtone) {
    Log.d(THIS_FILE, "==> ring() called...");

    synchronized (this) {

    	AudioManager audioManager =
            (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    	
    	//Save ringtone at the begining in case we raise vol
        Ringtone ringtone = getRingtone(remoteContact, defaultRingtone);
        ringerWorker.setRingtone(ringtone);
        
    	//No ring no vibrate
        int ringerMode = audioManager.getRingerMode();
        if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
        	Log.d(THIS_FILE, "skipping ring and vibrate because profile is Silent");
        	return;
        }
        
        // Vibrate
        int vibrateSetting = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
        Log.d(THIS_FILE, "v=" + vibrateSetting + " rm=" + ringerMode);
        if (vibratorThread == null &&
        		(vibrateSetting == AudioManager.VIBRATE_SETTING_ON || 
        				ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
            vibratorThread = new VibratorThread();
            Log.d(THIS_FILE, "Starting vibrator...");
            vibratorThread.start();
        }

        // Vibrate only
        if (ringerMode == AudioManager.RINGER_MODE_VIBRATE ||
        		audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0 ) {
        	Log.d(THIS_FILE, "skipping ring because profile is Vibrate OR because volume is zero");
        	return;
        }

        // Ringer normal, audio set for ring, do it
        if(ringtone == null) {
        	Log.d(THIS_FILE, "No ringtone available - do not ring");
        	return;
        }

        ringerWorker.startRinging(audioManager);
    	
    }
}
 
Example 19
Source File: Utils.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/** @return The next ringer mode according to the direction of the change. */
public static int nextRingerMode(final int direction, final int mRingerMode, final boolean hasVibrator) {
    if (direction == ADJUST_SAME) return mRingerMode;
    int newRingerMode = mRingerMode;
    if (hasVibrator) {
        if (direction == ADJUST_RAISE) {
            switch (mRingerMode) {
                case AudioManager.RINGER_MODE_VIBRATE:
                    newRingerMode = AudioManager.RINGER_MODE_NORMAL;
                    break;
                case AudioManager.RINGER_MODE_SILENT:
                    newRingerMode = AudioManager.RINGER_MODE_VIBRATE;
                    break;
                case AudioManager.RINGER_MODE_NORMAL:
                    newRingerMode = AudioManager.RINGER_MODE_SILENT;
                    break;
            }
        } else {
            switch (mRingerMode) {
                case AudioManager.RINGER_MODE_VIBRATE:
                    newRingerMode = AudioManager.RINGER_MODE_SILENT;
                    break;
                case AudioManager.RINGER_MODE_SILENT:
                    newRingerMode = AudioManager.RINGER_MODE_NORMAL;
                    break;
                case AudioManager.RINGER_MODE_NORMAL:
                    newRingerMode = AudioManager.RINGER_MODE_VIBRATE;
                    break;
            }
        }
    } else {
        // Without a vibrator, it's a binary state.
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_SILENT:
                newRingerMode = AudioManager.RINGER_MODE_NORMAL;
                break;
            case AudioManager.RINGER_MODE_NORMAL:
                newRingerMode = AudioManager.RINGER_MODE_SILENT;
                break;
        }
    }
    return newRingerMode;
}
 
Example 20
Source File: Notifications.java    From BlackList with Apache License 2.0 4 votes vote down vote up
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;
            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());
}