本文整理汇总了Java中android.media.AudioManager.setRingerMode方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.setRingerMode方法的具体用法?Java AudioManager.setRingerMode怎么用?Java AudioManager.setRingerMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.setRingerMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildUpdate
import android.media.AudioManager; //导入方法依赖的package包/类
private RemoteViews buildUpdate(Context context) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget);
AudioManager audioManager = (AudioManager) context.getSystemService(Activity.AUDIO_SERVICE);
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
updateViews.setImageViewResource(R.id.phoneState, R.drawable.phone_state_normal);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
} else {
updateViews.setImageViewResource(R.id.phoneState, R.drawable.phone_state_silent);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
Intent i = new Intent(this, AppWidget.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
updateViews.setOnClickPendingIntent(R.id.phoneState, pi);
return updateViews;
}
示例2: setRingerMode
import android.media.AudioManager; //导入方法依赖的package包/类
/**
* Changes the ringer mode on the device to either silent or back to normal
*
* @param context The context to access AUDIO_SERVICE
* @param mode The desired mode to switch device to, can be AudioManager.RINGER_MODE_SILENT or
* AudioManager.RINGER_MODE_NORMAL
*/
public static void setRingerMode(Context context, int mode){
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT<24 || (Build.VERSION.SDK_INT>=24 && !notificationManager.isNotificationPolicyAccessGranted())){
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(mode);
}
}
示例3: onMessageReceived
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
// Read the received ringer or dnd mode and convert it back to an integer
int newMode = Integer.parseInt(new String(messageEvent.getData()));
if (SEND_RINGER_MODE) {
Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
} else {
Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
}
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Check if the notification policy access has been granted for the app
// This is needed to set modes that affect Do Not Disturb in Android N
if (mNotificationManager.isNotificationPolicyAccessGranted()) {
if (SEND_RINGER_MODE) {
Log.d(TAG, "Attempting to set ringer mode " + newMode);
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (newMode == AudioManager.RINGER_MODE_SILENT) {
audioManager.setRingerMode(newMode);
} else {
// Set the saved "normal" value
audioManager.setRingerMode(getNormalRingerMode());
}
} else {
Log.d(TAG, "Attempting to set dnd mode " + newMode);
mNotificationManager.setInterruptionFilter(newMode);
}
} else {
Log.d(TAG, "App is not allowed to change Do Not Disturb mode without applying workaround");
}
} else {
super.onMessageReceived(messageEvent);
}
}
示例4: modeNormal
import android.media.AudioManager; //导入方法依赖的package包/类
public static void modeNormal(Activity activity){
checkPermissionForRingtone(activity);
AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
if(isModeNormal){
mobilemode.setRingerMode(mobileModeNormalPrevious);
isModeNormal = false;
}else {
isModeNormal = true;
mobileModeNormalPrevious = mobilemode.getRingerMode();
mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
}
示例5: onSwitched
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onSwitched(boolean isSwitched) {
AudioManager manager = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE);
if (manager == null) return;
// change audio settings
manager.setRingerMode(isSwitched ? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_SILENT);
// ringer notification is sent by Android itself
validateState(manager);
}
示例6: onItemClick
import android.media.AudioManager; //导入方法依赖的package包/类
public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
AudioManager manager = (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE);
if (manager != null) {
int ringerMode = AudioManager.RINGER_MODE_NORMAL;
int vibroMode = AudioManager.VIBRATE_SETTING_ON;
switch(index) {
case 0: // silent
ringerMode = AudioManager.RINGER_MODE_SILENT;
vibroMode = AudioManager.VIBRATE_SETTING_ONLY_SILENT;
break;
case 1: // vibro
ringerMode = AudioManager.RINGER_MODE_VIBRATE;
vibroMode = AudioManager.VIBRATE_SETTING_ON;
break;
case 2: // sound
ringerMode = AudioManager.RINGER_MODE_NORMAL;
vibroMode = AudioManager.VIBRATE_SETTING_OFF;
break;
case 3: // sound and vibro
ringerMode = AudioManager.RINGER_MODE_NORMAL;
vibroMode = AudioManager.VIBRATE_SETTING_ON;
break;
}
// update manager modes
// update
manager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, vibroMode);
manager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, vibroMode);
manager.setRingerMode(ringerMode);
validateState(manager);
}
mDialog.hide();
}
示例7: onValueChanged
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onValueChanged(int value) {
RangeSetting setting = (RangeSetting) mSetting;
setting.value = value;
int v = (int) (100f / 15 * value); // value in %
System.out.println("New value: " + setting.value + ", value%=" + v);
AudioManager manager = mManager;
// get max value for state
int maxv1 = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int maxv2 = manager.getStreamMaxVolume(AudioManager.STREAM_RING);
int maxv3 = manager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
int maxv4 = manager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
// get current volumes
int v1, v2, v3, v4;
manager.setStreamVolume(AudioManager.STREAM_MUSIC, v1 = round(maxv1 * v / 100f), AudioManager.FLAG_PLAY_SOUND);
manager.setStreamVolume(AudioManager.STREAM_RING, v2 = round(maxv2 * v / 100f), 0);
manager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, v3 = round(maxv3 * v / 100f), 0);
manager.setStreamVolume(AudioManager.STREAM_ALARM, v4 = round(maxv4 * v / 100f), 0);
if (manager.getRingerMode() == AudioManager.RINGER_MODE_SILENT & v2 > 0) {
manager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
} else if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT && v2 == 0) {
manager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
setting.descr = mActivity.getString(R.string.txt_master_volume_desc, v2, v3, v1, v4);
setting.updateView();
}
示例8: initAudioManager
import android.media.AudioManager; //导入方法依赖的package包/类
private void initAudioManager() {
mAudioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);
int mode = mAudioManager.getRingerMode();
if (mode == AudioManager.RINGER_MODE_VIBRATE
|| mode == AudioManager.RINGER_MODE_SILENT) {
// Normal mode will be audible and may vibrate according to user settings.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
NotificationManager n = (NotificationManager) mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
boolean isPolicyGranted = n != null && n.isNotificationPolicyAccessGranted();
// fixme 7.0手机 如果没有这个权限 直接调用setRingerMode会报出 Not allowed to change Do Not Disturb state的异常.
if (isPolicyGranted) {
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
} else {
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
}
mAudioMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int audioCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
if (mAudioMaxVolume != 0) {
mCurrentVolume = (int) (((float) audioCurrentVolume / (float) mAudioMaxVolume) * 100);
}
PlayerLog.d(TAG, "initAudioManager mCurrentVolume is " + mCurrentVolume +
" , mAudioMaxVolume is " + mAudioMaxVolume +
" , audioCurrentVolume is " + audioCurrentVolume);
}
示例9: preparePhoneToPlayAudio
import android.media.AudioManager; //导入方法依赖的package包/类
private void preparePhoneToPlayAudio(Context context) {
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
originalRingerMode = audioManager.getRingerMode();
originalRingerMode = audioManager.getRingerMode();
originalRingerVolume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
if(originalRingerMode != AudioManager.RINGER_MODE_NORMAL) {
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, audioManager.getStreamMaxVolume
(AudioManager.STREAM_NOTIFICATION), 0);
}
示例10: 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();
}
}
}
示例11: modeVibrate
import android.media.AudioManager; //导入方法依赖的package包/类
public static void modeVibrate(Activity activity){
checkPermissionForRingtone(activity);
AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
if(isModeVibrate){
mobilemode.setRingerMode(mobileModeVibratePrevious);
isModeVibrate = false;
}else {
isModeVibrate = true;
mobileModeVibratePrevious = mobilemode.getRingerMode();
mobilemode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
}
示例12: changeRingerMode
import android.media.AudioManager; //导入方法依赖的package包/类
private static void changeRingerMode(Intent intent) {
try {
int mode = intent.getIntExtra(EXTRA_RINGER_MODE, RingerModeShortcut.MODE_RING_VIBRATE);
AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
ContentResolver cr = mContext.getContentResolver();
int msgResId = 0;
switch (mode) {
case RingerModeShortcut.MODE_RING:
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Settings.System.putInt(cr, SETTING_VIBRATE_WHEN_RINGING, 0);
msgResId = R.string.ringer_mode_sound;
break;
case RingerModeShortcut.MODE_RING_VIBRATE:
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Settings.System.putInt(cr, SETTING_VIBRATE_WHEN_RINGING, 1);
msgResId = R.string.ringer_mode_sound_vibrate;
break;
case RingerModeShortcut.MODE_SILENT:
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
msgResId = R.string.dnd_tile_em_alarms;
break;
case RingerModeShortcut.MODE_VIBRATE:
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Settings.System.putInt(cr, SETTING_VIBRATE_WHEN_RINGING, 1);
msgResId = R.string.ringer_mode_vibrate;
break;
}
if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
Utils.postToast(mContext, msgResId);
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
示例13: 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);
}
}
示例14: modeSilent
import android.media.AudioManager; //导入方法依赖的package包/类
public static void modeSilent(Activity activity){
checkPermissionForRingtone(activity);
AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
if(isModeSilent){
mobilemode.setRingerMode(mobileModeSilentPrevious);
isModeSilent = false;
}else {
isModeSilent = true;
mobileModeSilentPrevious = mobilemode.getRingerMode();
mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
示例15: onMessageReceived
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d(TAG, "onMessageReceived: " + messageEvent);
switch (messageEvent.getPath()) {
case PATH_DND:
if (messageEvent.getData().length == 0)
return;
int state = (int) messageEvent.getData()[0];
Log.d(TAG, "Target state: " + state);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (state != NotificationManager.INTERRUPTION_FILTER_ALL)
state = NotificationManager.INTERRUPTION_FILTER_ALARMS;
if (state == (int) notificationManager.getCurrentInterruptionFilter())
return;
if (notificationManager.isNotificationPolicyAccessGranted())
notificationManager.setInterruptionFilter(state);
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = new Intent(LGHackService.ACTION_SET_STATE);
intent.putExtra(LGHackService.EXTRA_STATE, (int) messageEvent.getData()[0]);
sendBroadcast(intent);
} else {
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
state = state == 4 ? AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_NORMAL;
//INTERRUPTION_FILTER_ALARMS
if (state == audioManager.getRingerMode())
return;
audioManager.setRingerMode(state);
}
return;
case PATH_DND_REGISTER:
if (messageEvent.getData().length == 0)
return;
Intent connectIntent = new Intent(WEAR_CALLBACK_CONNECT);
if (messageEvent.getData().length > 1) {
DataMap config = DataMap.fromByteArray(messageEvent.getData());
connectIntent.putExtra("permission", config.getBoolean("permission"));
}
sendBroadcast(connectIntent);
Log.d(TAG, "Connected broadcast");
return;
case PATH_LOGS:
if (messageEvent.getData().length == 0)
return;
Intent logIntent = new Intent(WEAR_CALLBACK_LOGS);
logIntent.putExtra("log", new String(messageEvent.getData()));
sendBroadcast(logIntent);
Log.d(TAG, "Logs broadcast");
return;
}
}