@SuppressWarnings("deprecation") public static void getAudioRoute(AudioManager am) { if (am.isBluetoothA2dpOn()) { am.setBluetoothA2dpOn(true); } else if (am.isSpeakerphoneOn()) { am.setSpeakerphoneOn(true); } else if (am.isWiredHeadsetOn()) { am.setWiredHeadsetOn(true); } }
private int getCurrentAudioPathOtherThanA2dp() { AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); if (manager == null) return AUDIO_PATH_UNKNOWN; // This method was deprecated in API level 14. // Use only to check is a headset is connected or not. boolean result = manager.isWiredHeadsetOn(); if (result) { return AUDIO_PATH_WIRED; } // setSpeakerphoneOn does not work well... return AUDIO_PATH_SPEAKER; }
// Checks if the wind anemometer is connected public boolean checkMeterConnected() { AudioManager audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); if (!audio.isWiredHeadsetOn()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Wind anemometer is not plugged in"); builder.setMessage("Please plug in the anemometer"); builder.setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) {} }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); return false; } else { return true; } }
/** * Returns whether the device should obscure typed password characters. Typically this means * speaking "dot" in place of non-control characters. * * @return {@code true} if the device should obscure password characters. */ @SuppressWarnings("deprecation") public boolean shouldObscureInput(final EditorInfo editorInfo) { if (editorInfo == null) return false; // The user can optionally force speaking passwords. if (SettingsSecureCompatUtils.ACCESSIBILITY_SPEAK_PASSWORD != null) { final boolean speakPassword = Settings.Secure.getInt( mContext.getContentResolver(), SettingsSecureCompatUtils.ACCESSIBILITY_SPEAK_PASSWORD, 0) != 0; if (speakPassword) return false; } // Always speak if the user is listening through headphones. if (mAudioManager.isWiredHeadsetOn() || mAudioManager.isBluetoothA2dpOn()) { return false; } // Don't speak if the IME is connected to a password field. return InputTypeUtils.isPasswordInputType(editorInfo.inputType); }
/** * Checks whether a wired headset is connected or not. This is not a valid indication that audio * playback is actually over the wired headset as audio routing depends on other conditions. We * only use it as an early indicator (during initialization) of an attached wired headset. */ @Deprecated private boolean hasWiredHeadset() { return audioManager.isWiredHeadsetOn(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new UnhandledExceptionHandler(this)); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Point displaySize = new Point(); getWindowManager().getDefaultDisplay().getRealSize(displaySize); vsv = new AppRTCGLView(this, displaySize); VideoRendererGui.setView(vsv); remoteRender = VideoRendererGui.create(0, 0, 100, 100); localRender = VideoRendererGui.create(70, 5, 25, 25); vsv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { toggleHUD(); } }); setContentView(vsv); logAndToast("Tap the screen to toggle stats visibility"); hudView = new TextView(this); hudView.setTextColor(Color.BLACK); hudView.setBackgroundColor(Color.WHITE); hudView.setAlpha(0.4f); hudView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5); hudView.setVisibility(View.INVISIBLE); addContentView(hudView, hudLayout); if (!factoryStaticInitialized) { abortUnless( PeerConnectionFactory.initializeAndroidGlobals(this, true, true), "Failed to initializeAndroidGlobals"); factoryStaticInitialized = true; } AudioManager audioManager = ((AudioManager) getSystemService(AUDIO_SERVICE)); // TODO(fischman): figure out how to do this Right(tm) and remove the // suppression. @SuppressWarnings("deprecation") boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn(); audioManager.setMode( isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION); audioManager.setSpeakerphoneOn(!isWiredHeadsetOn); sdpMediaConstraints = new MediaConstraints(); sdpMediaConstraints.mandatory.add( new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); sdpMediaConstraints.mandatory.add( new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); final Intent intent = getIntent(); if ("android.intent.action.VIEW".equals(intent.getAction())) { connectToRoom(intent.getData().toString()); return; } showGetRoomUI(); }
/** * 判断耳机是否插上 * * @return */ public static boolean isWiredHeadsetOn(Context context) { AudioManager localAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return localAudioManager.isWiredHeadsetOn(); }
private void ad(String paramString) { Uri localUri; MediaPlayer localMediaPlayer; if (paramString == SettingsRingtoneUI.cRA) { localUri = RingtoneManager.getDefaultUri(2); localMediaPlayer = new MediaPlayer(); } while (true) { int k; try { localMediaPlayer.setDataSource(this.context, localUri); AudioManager localAudioManager = (AudioManager)this.context.getSystemService("audio"); if (localAudioManager.getStreamVolume(5) != 0) { if (localAudioManager.isWiredHeadsetOn()) { int i = localAudioManager.getStreamVolume(8); j = localAudioManager.getStreamMaxVolume(8); k = localAudioManager.getStreamVolume(5); if (k <= j) break label217; localAudioManager.setStreamVolume(8, j, 0); localMediaPlayer.setAudioStreamType(8); localMediaPlayer.setLooping(true); localMediaPlayer.prepare(); localMediaPlayer.setLooping(false); localMediaPlayer.start(); localAudioManager.setStreamVolume(8, i, 0); Object[] arrayOfObject = new Object[2]; arrayOfObject[0] = Integer.valueOf(i); arrayOfObject[1] = Integer.valueOf(j); n.e("MicroMsg.MMNotification", "oldVolume is %d, toneVolume is %d", arrayOfObject); } } else { return; localUri = Uri.parse(paramString); break; } localMediaPlayer.setAudioStreamType(5); localMediaPlayer.setLooping(true); localMediaPlayer.prepare(); localMediaPlayer.setLooping(false); localMediaPlayer.start(); return; } catch (IllegalArgumentException localIllegalArgumentException) { return; } catch (IOException localIOException) { return; } catch (IllegalStateException localIllegalStateException) { return; } catch (SecurityException localSecurityException) { return; } label217: int j = k; } }