本文整理汇总了Java中android.media.AudioManager.getRingerMode方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.getRingerMode方法的具体用法?Java AudioManager.getRingerMode怎么用?Java AudioManager.getRingerMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.getRingerMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
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;
}
示例2: onResume
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "xxxxxxxxxxxxxxxxxxxonResume");
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;
final AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
playBeep = false;
}
initBeepSound();
vibrate = true;
}
示例3: onResume
import android.media.AudioManager; //导入方法依赖的package包/类
@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;
}
示例4: onResume
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
if (hasSurface) {
initCamera(surfaceHolder);
} else {
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
decodeFormats = null;
characterSet = null;
// playBeep = true;
AudioManager audioService = (AudioManager) getActivity().getSystemService(getActivity().AUDIO_SERVICE);
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
playBeep = false;
}
initBeepSound();
// vibrate = true;
}
示例5: playRingtone
import android.media.AudioManager; //导入方法依赖的package包/类
void playRingtone(Context context) {
if (mMediaPlayer == null) {
initialize();
}
if (!mMediaPlayer.isPlaying() && !mMediaPlayer.isLooping()) {
try {
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mMediaPlayer.setDataSource(context, sound);
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
beforeRingerMode = audioManager.getRingerMode();
try {
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
} catch(SecurityException se) {
se.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null) {
interruptionFilterBefore = mNotificationManager.getCurrentInterruptionFilter();
mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL);
} else {
Log.w("ALARM", "Can't access system service NotificationManager");
}
}
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) > 0) {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.prepare();
mMediaPlayer.start();
}
}
} catch (IOException | IllegalStateException e) {
e.printStackTrace();
mMediaPlayer.reset();
}
}
}
示例6: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
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;
}
示例7: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
boolean shouldPlayBeep = Config.ConfigType.KEY_PLAY_BEEP.enable();
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;
}
示例8: start
import android.media.AudioManager; //导入方法依赖的package包/类
public void start() {
AudioManager audioManager = ServiceUtil.getAudioManager(context);
if (player != null) player.release();
player = createPlayer();
int ringerMode = audioManager.getRingerMode();
if (shouldVibrate(context, player, ringerMode)) {
Log.i(TAG, "Starting vibration");
vibrator.vibrate(VIBRATE_PATTERN, 1);
}
if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
try {
if (!player.isPlaying()) {
player.prepare();
player.start();
Log.w(TAG, "Playing ringtone now...");
} else {
Log.w(TAG, "Ringtone is already playing, declining to restart.");
}
} catch (IllegalStateException | IOException e) {
Log.w(TAG, e);
player = null;
}
} else {
Log.w(TAG, "Not ringing, mode: " + ringerMode);
}
}
示例9: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
boolean shouldPlayBeep = true; //prefs.getBoolean(PreferencesActivity.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;
}
示例10: volumeProfileEnabled
import android.media.AudioManager; //导入方法依赖的package包/类
/**
* Check if the device can currently output sound, by checking the media profile. This is unfortunately
* not foolproof, due to the various ways different ROM and device manufacturers link the stream types.
*
* @param audioManager object
* @return true if the device will output sounds, false otherwise
*/
private static boolean volumeProfileEnabled(@NonNull final AudioManager audioManager) {
switch (audioManager.getRingerMode()) {
case AudioManager.RINGER_MODE_NORMAL:
if (DEBUG) {
MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_NORMAL");
}
return true;
case AudioManager.RINGER_MODE_VIBRATE:
if (DEBUG) {
MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_VIBRATE");
}
break;
case AudioManager.RINGER_MODE_SILENT:
if (DEBUG) {
MyLog.i(CLS_NAME, "volumeProfileEnabled: RINGER_MODE_SILENT");
}
break;
default:
if (DEBUG) {
MyLog.w(CLS_NAME, "volumeProfileEnabled: Default");
}
break;
}
return false;
}
示例11: disableSoundAndVibration
import android.media.AudioManager; //导入方法依赖的package包/类
private void disableSoundAndVibration() {
AudioManager audioManager = (AudioManager) getActivity().getApplicationContext()
.getSystemService(Context.AUDIO_SERVICE);
mPreviousRingerMode = audioManager.getRingerMode();
if(mPreviousRingerMode != AudioManager.RINGER_MODE_SILENT){
Log.d(TAG, "Disabling sound and vibration");
ringerModeChanged = true;
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
示例12: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
boolean shouldPlayBeep = prefs.getBoolean(PreferencesActivity.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;
}
示例13: hideVibrateIcon
import android.media.AudioManager; //导入方法依赖的package包/类
private void hideVibrateIcon() {
if (mSbService == null || mContext == null) return;
try {
AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
XposedHelpers.callMethod(mSbService, "setIconVisibility", "volume", false);
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
示例14: shouldBeep
import android.media.AudioManager; //导入方法依赖的package包/类
private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
boolean shouldPlayBeep = prefs.getBoolean(activity.getString(R.string.preferences_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;
}
示例15: onClick
import android.media.AudioManager; //导入方法依赖的package包/类
public void onClick(DialogInterface dialog, int whichButton) {
if (BUTTON_CANCEL == whichButton) {
return; // stop on cancel
}
Activity activity = mActivity;
// cache
final AudioManager manager = (AudioManager) activity.getSystemService(Activity.AUDIO_SERVICE);
final int[] volumes = mVolumes;
final SeekBar[] seekBars = mSeekBars;
final int[] streamTypes = STREAM_TYPES;
// apply changes
final int length = seekBars.length;
boolean prevChanged = false;
for (int i = 0; i<length; i++) {
// get control
int value = seekBars[i].getProgress();
boolean isNotification = i == 1;
boolean changed = value != volumes[i]
|| (isNotification && prevChanged);
if (changed) {
manager.setStreamVolume(streamTypes[i], value, 0);
//Log.d(TAG, "updating index: " + i + ", value: " + value);
}
if (isNotification) {
// if notification change updated volume as well we should return volume back (2.0 behavior)
int ringerVolumeDesired = seekBars[0].getProgress();
int ringerVolumeActual = manager.getStreamVolume(streamTypes[0]);
if (ringerVolumeDesired != ringerVolumeActual) {
manager.setStreamVolume(streamTypes[0], ringerVolumeDesired, 0);
//Log.d(TAG, "changing ringer volume to desired value: " + + value);
}
}
prevChanged = changed;
}
// check if we have to switch silent / not silen mode
int ringerVolume = manager.getStreamVolume(AudioManager.STREAM_RING);
int notifVolume = manager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
int ringerMode = manager.getRingerMode();
if (ringerVolume > 0 && ringerMode == AudioManager.RINGER_MODE_SILENT) {
Toast.makeText(activity, activity.getString(R.string.msg_not_silent_warning, ringerVolume), Toast.LENGTH_LONG).show();
} else if (ringerVolume == 0 && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
Toast.makeText(activity, R.string.msg_zero_ringer_warning, Toast.LENGTH_LONG).show();
} else if (notifVolume == 0 && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
Toast.makeText(activity, R.string.msg_zero_notification_warning, Toast.LENGTH_LONG).show();
}
// send internal volume changed notification
activity.sendBroadcast(new Intent(Constants.ACTION_VOLUME_UPDATED));
}