Java Code Examples for android.media.AudioManager#RINGER_MODE_NORMAL

The following examples show how to use android.media.AudioManager#RINGER_MODE_NORMAL . 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: CaptureActivity.java    From lunzi with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}
 
Example 2
Source File: CaptureActivity.java    From QrScan with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化照相机和surfaceView,使zxing不断尝试从摄像头获取照片并解码
 * 本方法在Activity的onResume中,以及在扫描功能被关闭后需要再次开启时调用
 */
private void initZXingCamera() {
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }

    vibrate = true;
}
 
Example 3
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private boolean isLoudPhone(Context ctx) {
    final AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
    try {
        switch (am.getRingerMode()) {
            case AudioManager.RINGER_MODE_SILENT:
                return false;
            case AudioManager.RINGER_MODE_VIBRATE:
                return false;
            case AudioManager.RINGER_MODE_NORMAL:
                return true;
        }
    } catch (NullPointerException e) {
        UserError.Log.e(TAG,"Got null pointer exception from isLoudPhone");
    }
    // unknown mode, not sure let's play just in any case.
    return true;
}
 
Example 4
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 5
Source File: SoundUtil.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**
 * Plays sound with the phone sound settings.
 * @param context
 * @param rawSoundId
 * @param vibrateMillies
 */
public static void playSoundWithUserSettings(Context context, int rawSoundId, int vibrateMillies) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            vibrate(context, vibrateMillies);
            break;
        case AudioManager.RINGER_MODE_NORMAL:
            playRawSound(rawSoundId, context);
            vibrate(context, vibrateMillies);
            break;
    }
}
 
Example 6
Source File: BeepManager.java    From Android with MIT License 5 votes vote down vote up
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
	boolean shouldPlayBeep = true;
	if (shouldPlayBeep) {
		// See if sound settings overrides this
		AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
		if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
			shouldPlayBeep = false;
		}
	}
	return shouldPlayBeep;
}
 
Example 7
Source File: CaptureActivity.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
protected void onResume()
{
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface)
    {
        initCamera(surfaceHolder);
    }
    else
    {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
    {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}
 
Example 8
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 9
Source File: Sound.java    From homescreenarcade with GNU General Public License v3.0 5 votes vote down vote up
public void tetrisSound() {
	if(noFocus)
		return;
	if(audioCEO.getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
		return;
	soundPool.play(
		soundID_tetrisSoundPlayer,
		0.01f * PreferenceManager.getDefaultSharedPreferences(host).getInt("pref_soundvolume", 60), 
		0.01f * PreferenceManager.getDefaultSharedPreferences(host).getInt("pref_soundvolume", 60), 
		1, 
		0, 
		1.0f
	);
}
 
Example 10
Source File: KcaAlarmService.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
private NotificationCompat.Builder setSoundSetting(NotificationCompat.Builder builder) {
    String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
    if (soundKind.equals(getString(R.string.sound_kind_value_normal)) || soundKind.equals(getString(R.string.sound_kind_value_mixed))) {
        if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
            if (soundKind.equals(getString(R.string.sound_kind_value_mixed))) {
                builder.setDefaults(Notification.DEFAULT_VIBRATE);
            }
            Uri content_uri = getContentUri(getApplicationContext(),
                    Uri.parse(getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_RINGTONE)));
            builder.setSound(content_uri);
        } else if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
        } else {
            builder.setDefaults(0);
        }
    }
    if (soundKind.equals(getString(R.string.sound_kind_value_vibrate))) {
        if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
        } else {
            builder.setDefaults(0);
        }
    }
    if (soundKind.equals(getString(R.string.sound_kind_value_mute))) {
        builder.setDefaults(0);
    }
    return builder;
}
 
Example 11
Source File: BeepManager.java    From ZXingProject with MIT License 5 votes vote down vote up
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
	boolean shouldPlayBeep = true;
	if (shouldPlayBeep) {
		// See if sound settings overrides this
		AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
		if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
			shouldPlayBeep = false;
		}
	}
	return shouldPlayBeep;
}
 
Example 12
Source File: BeepManager.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
    boolean shouldPlayBeep = true;
    if (shouldPlayBeep) {
        // See if sound settings overrides this
        AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
        if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
            shouldPlayBeep = false;
        }
    }
    return shouldPlayBeep;
}
 
Example 13
Source File: BeepManager.java    From YZxing with Apache License 2.0 5 votes vote down vote up
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
    boolean shouldPlayBeep = prefs.getBoolean(Constant.KEY_PLAY_BEEP, true);
    if (shouldPlayBeep) {
        // See if sound settings overrides this
        AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
        if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
            shouldPlayBeep = false;
        }
    }
    return shouldPlayBeep;
}
 
Example 14
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 15
Source File: InterruptionFilterChangedBroadcastReceiver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    //CallsCounter.logCounter(context, "InterruptionFilterChangedBroadcastReceiver.onReceive", "InterruptionFilterChangedBroadcastReceiver_onReceive");

    //if (android.os.Build.VERSION.SDK_INT >= 23) {
        boolean no60 = !Build.VERSION.RELEASE.equals("6.0");
        if (no60 && GlobalGUIRoutines.activityActionExists(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS, context)) {
            if (!RingerModeChangeReceiver.internalChange) {

                NotificationManager mNotificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                if (mNotificationManager != null) {
                    int interruptionFilter = mNotificationManager.getCurrentInterruptionFilter();
                    final AudioManager audioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
                    int ringerMode = AudioManager.RINGER_MODE_NORMAL;
                    if (audioManager != null)
                        ringerMode = audioManager.getRingerMode();

                    // convert to profile zenMode
                    int zenMode = 0;
                    switch (interruptionFilter) {
                        case NotificationManager.INTERRUPTION_FILTER_ALL:
                            //if (ActivateProfileHelper.vibrationIsOn(/*context.getApplicationContext(), */audioManager, true))
                            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                                zenMode = 4;
                            else
                                zenMode = 1;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                            //if (ActivateProfileHelper.vibrationIsOn(/*context.getApplicationContext(), */audioManager, true))
                            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                                zenMode = 5;
                            else
                                zenMode = 2;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_NONE:
                            zenMode = 3;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                            zenMode = 6;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_UNKNOWN:
                            zenMode = 1;
                            break;
                    }
                    //PPApplication.logE(TAG, "onReceive(zenMode=" + zenMode + ')');
                    if (zenMode != 0) {
                        RingerModeChangeReceiver.notUnlinkVolumes = true;
                        ActivateProfileHelper.saveRingerMode(context.getApplicationContext(), 5);
                        ActivateProfileHelper.saveZenMode(context.getApplicationContext(), zenMode);
                    }
                }
            }

            //RingerModeChangeReceiver.setAlarmForDisableInternalChange(getApplicationContext());
        }
    //}
}
 
Example 16
Source File: RingerModeTracker.java    From Easer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void stop() {
    context.unregisterReceiver(broadcastReceiver);
    if (condition.ringerMode == AudioManager.RINGER_MODE_NORMAL)
        context.getContentResolver().unregisterContentObserver(settingsObserver);
}
 
Example 17
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());
}
 
Example 18
Source File: RingerModeChangeReceiver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private static int getRingerMode(Context context, AudioManager audioManager) {
    int ringerMode = audioManager.getRingerMode();

    //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "ringerMode="+ringerMode);

    // convert to profile ringerMode
    int pRingerMode = 0;
    //if (android.os.Build.VERSION.SDK_INT >= 21) {
        int systemZenMode = ActivateProfileHelper.getSystemZenMode(context/*, -1*/);
        //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "systemZenMode=" + systemZenMode);
        if (systemZenMode == ActivateProfileHelper.ZENMODE_ALL) {
            switch (ringerMode) {
                case AudioManager.RINGER_MODE_NORMAL:
                    //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, false))
                    //    pRingerMode = 2;
                    //else
                        pRingerMode = 1;
                    break;
                case AudioManager.RINGER_MODE_VIBRATE:
                    pRingerMode = 3;
                    break;
                case AudioManager.RINGER_MODE_SILENT:
                    pRingerMode = 4;
                    break;
            }
        }
        else
            pRingerMode = 5;
    /*}
    else {
        switch (ringerMode) {
            case AudioManager.RINGER_MODE_NORMAL:
                if (ActivateProfileHelper.vibrationIsOn(audioManager, false))
                    pRingerMode = 2;
                else
                    pRingerMode = 1;
                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                pRingerMode = 3;
                break;
            case AudioManager.RINGER_MODE_SILENT:
                pRingerMode = 4;
                break;
        }
    }*/

    //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "pRingerMode=" + pRingerMode);

    return pRingerMode;
}
 
Example 19
Source File: AudioAndHapticFeedbackManager.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
private boolean reevaluateIfSoundIsOn() {
    if (mSettingsValues == null || !mSettingsValues.mSoundOn || mAudioManager == null) {
        return false;
    }
    return mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
}
 
Example 20
Source File: ActivityCallViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
public void playRingtone() {
    boolean canPlay = false;
    AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE);

    switch (am.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            canPlay = false;
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            canPlay = false;

            vibrator = (Vibrator) G.context.getSystemService(Context.VIBRATOR_SERVICE);
            long[] pattern = {0, 100, 1000};
            vibrator.vibrate(pattern, 0);

            break;
        case AudioManager.RINGER_MODE_NORMAL:
            canPlay = true;
            break;
    }

    if (am.isWiredHeadsetOn()) {
        canPlay = true;
    }

    if (canPlay) {

        try {
            Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            String path = AttachFile.getFilePathFromUri(alert);

            ringtonePlayer = new MediaPlayer();

            if (path == null) {
                ringtonePlayer.setDataSource(context, Uri.parse("android.resource://" + G.context.getPackageName() + "/" + R.raw.tone));
            } else {
                ringtonePlayer.setDataSource(G.context, alert);
            }

            if (am.isWiredHeadsetOn()) {
                ringtonePlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
            } else {
                ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
            }

            ringtonePlayer.setLooping(true);
            ringtonePlayer.prepare();
            ringtonePlayer.start();
        } catch (Exception e) {
            HelperLog.setErrorLog("activity call view model   set ringtone uri  " + e);
        }
    }

    startRingAnimation();
}