List of usage examples for android.media AudioManager STREAM_RING
int STREAM_RING
To view the source code for android.media AudioManager STREAM_RING.
Click Source Link
From source file:com.app.blockydemo.ui.ScriptActivity.java
@Override protected void onDestroy() { super.onDestroy(); setVolumeControlStream(AudioManager.STREAM_RING); }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
public boolean isPhoneMuted() { final AudioManager audioMan = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return audioMan.getStreamVolume(AudioManager.STREAM_RING) == 0; }
From source file:com.xortech.sender.SmsReceiver.java
public void onReceive(final Context ctx, Intent intent) { // GET SMS MAP FROM INTENT Bundle extras = intent.getExtras();//from w ww . j av a 2 s .c o m context = ctx; // GPS INSTANCE gps = new GPSTracker(context); // LOAD PREFERENCES preferences = PreferenceManager.getDefaultSharedPreferences(context); secretCode = preferences.getString("secretCode", DEFAULT_CODE); tagID = preferences.getString("tagID", DEFAULT_TAGID); senderEnabled = preferences.getBoolean("senderEnabled", true); if (extras != null) { // GET THE RECEIVED SMS ARRAY Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME); for (int i = 0; i < smsExtra.length; ++i) { // GET THE MESSAGE SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); // PARSE THE MESSAGE BODY String body = sms.getMessageBody().toString(); String address = sms.getOriginatingAddress(); long time = System.currentTimeMillis(); // GET COORDINATES AND SEND A MESSAGE gps.getLocation(); latitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLatitude()) / FIVE_DIGIT); longitude = String.valueOf(Math.round(FIVE_DIGIT * gps.getLongitude()) / FIVE_DIGIT); location = "Tag_ID:" + tagID + ":Location:" + latitude + "," + longitude; googleString = GOOGLE_STRING + latitude + "," + longitude + "(" + tagID + ")"; if (body.equals(SECRET_LOCATION_A + secretCode)) { if (senderEnabled) { if (latitude.equals("0.0") | longitude.equals("0.0")) { SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null); } else { SmsManager.getDefault().sendTextMessage(address, null, googleString, null, null); } } this.abortBroadcast(); } else if (body.equals(SECRET_LOCATION_B + secretCode)) { if (senderEnabled) { if (latitude.equals("0.0") | longitude.equals("0.0")) { SmsManager.getDefault().sendTextMessage(address, null, NO_COORDS + tagID, null, null); } else { SmsManager.getDefault().sendTextMessage(address, null, location, null, null); } } this.abortBroadcast(); } else if (body.contains("Tag_ID:")) { // ADD TO DATABASE MsgDatabaseHandler dbHandler = new MsgDatabaseHandler(context); // VERIFY IF THE TAG EXISTS IN THE ARRAY String addressExists = VerifyTagExist(address); String[] splitBody = body.split(":"); String tag = splitBody[1]; tag.trim(); String coords = splitBody[3]; String[] splitCoords = coords.split(","); String lat = splitCoords[0]; lat.trim(); String lon = splitCoords[1]; lon.trim(); String _time = String.valueOf(time); String toastMsg = null; // CHECK IF THE ADDRESS EXISTS FOR NAMING PURPOSES if (addressExists == null) { dbHandler.Add_Message(new MessageData(tag, address, lat, lon, _time)); toastMsg = "Response Received: " + tag; } else { dbHandler.Add_Message(new MessageData(addressExists, address, lat, lon, _time)); toastMsg = "Response Received: " + addressExists; } dbHandler.close(); Toast.makeText(context, toastMsg, Toast.LENGTH_LONG).show(); this.abortBroadcast(); } else if (body.contains("Panic!")) { // OVERRIDE THE SILENT FEATURE AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, max, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); // DEFINE THE NOTIFICATION MANAGER notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // START A TIMER mytimer = new Timer(true); // SOUND LOCATION ALARM soundUri = Uri.parse(BEGIN_PATH + context.getPackageName() + FILE_PATH); // DISPLAY TAG ID FOR EMERGENCY String[] splitBody = body.split("\n"); String fieldTag = splitBody[1]; String[] splitTag = fieldTag.split(":"); emergencyTag = splitTag[1].trim(); // TIMER FOR NOTIFICATIONS mytask = new TimerTask() { public void run() { // RUN NOTIFICATION ON TIMER NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.emergency).setContentTitle(PANIC_TXT) .setContentText(emergencyTag + UNDER_DURRESS).setSound(soundUri); //This sets the sound to play // DISPLAY THE NOTIFICATION notificationManager.notify(0, mBuilder.build()); } }; // START TIMER AFTER 5 SECONDS mytimer.schedule(mytask, FIVE_SECONDS); } } } // CLEAR THE CACHE ON RECEIVING A MESSAGE try { MyUpdateReceiver.trimCache(context); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.wso2.iot.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *//*w w w .j av a 2 s. c o m*/ @TargetApi(21) private void startRing() { if (audio != null) { ringerMode = audio.getRingerMode(); ringerVolume = audio.getStreamVolume(AudioManager.STREAM_RING); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:org.wso2.emm.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *///from w w w. j a v a 2 s .com @TargetApi(21) private void startRing() { if (audio != null) { audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static void onState(int state, String caller) { if (ccCall == null) { ccCall = new Call(); ccConn = new Connection(); ccCall.setConn(ccConn);/*from www . j av a 2 s . co m*/ ccConn.setCall(ccCall); } if (call_state != state) { if (state != UserAgent.UA_STATE_IDLE) call_end_reason = -1; call_state = state; switch (call_state) { case UserAgent.UA_STATE_INCOMING_CALL: enable_wifi(true); RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; String text = caller.toString(); if (text.indexOf("<sip:") >= 0 && text.indexOf("@") >= 0) text = text.substring(text.indexOf("<sip:") + 5, text.indexOf("@")); String text2 = caller.toString(); if (text2.indexOf("\"") >= 0) text2 = text2.substring(text2.indexOf("\"") + 1, text2.lastIndexOf("\"")); broadcastCallStateChanged("RINGING", caller); mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ccCall.setState(Call.State.INCOMING); ccConn.setUserData(null); ccConn.setAddress(text, text2); ccConn.setIncoming(true); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int rm = am.getRingerMode(); int vs = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); KeyguardManager mKeyguardManager = (KeyguardManager) mContext .getSystemService(Context.KEYGUARD_SERVICE); if (v == null) v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); if ((pstn_state == null || pstn_state.equals("IDLE")) && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON) && !mKeyguardManager.inKeyguardRestrictedInputMode()) v.vibrate(vibratePattern, 1); else { if ((pstn_state == null || pstn_state.equals("IDLE")) && (rm == AudioManager.RINGER_MODE_VIBRATE || (rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON))) v.vibrate(vibratePattern, 1); if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) { String sUriSipRingtone = PreferenceManager.getDefaultSharedPreferences(mContext).getString( org.sipdroid.sipua.ui.Settings.PREF_SIPRINGTONE, Settings.System.DEFAULT_RINGTONE_URI.toString()); if (!TextUtils.isEmpty(sUriSipRingtone)) { oRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(sUriSipRingtone)); if (oRingtone != null) oRingtone.play(); } } } moveTop(); if (wl == null) { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.onState"); } wl.acquire(); Checkin.checkin(true); break; case UserAgent.UA_STATE_OUTGOING_CALL: RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; onText(MISSED_CALL_NOTIFICATION, null, 0, 0); engine(mContext).register(); broadcastCallStateChanged("OFFHOOK", caller); ccCall.setState(Call.State.DIALING); ccConn.setUserData(null); ccConn.setAddress(caller, caller); ccConn.setIncoming(false); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; moveTop(); Checkin.checkin(true); break; case UserAgent.UA_STATE_IDLE: broadcastCallStateChanged("IDLE", null); onText(CALL_NOTIFICATION, null, 0, 0); ccCall.setState(Call.State.DISCONNECTED); if (listener_video != null) listener_video.onHangup(); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); ccConn.log(ccCall.base); ccConn.date = 0; engine(mContext).listen(); break; case UserAgent.UA_STATE_INCALL: broadcastCallStateChanged("OFFHOOK", null); if (ccCall.base == 0) { ccCall.base = SystemClock.elapsedRealtime(); } progress(); ccCall.setState(Call.State.ACTIVE); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); break; case UserAgent.UA_STATE_HOLD: onText(CALL_NOTIFICATION, mContext.getString(R.string.card_title_on_hold), android.R.drawable.stat_sys_phone_call_on_hold, ccCall.base); ccCall.setState(Call.State.HOLDING); if (InCallScreen.started && (pstn_state == null || !pstn_state.equals("RINGING"))) mContext.startActivity(createIntent(InCallScreen.class)); break; } pos(true); RtpStreamReceiver.ringback(false); } }
From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java
private void playRingtone() { AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); if ((audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) || (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0)) { vibrate();/*from w w w. j av a 2 s.co m*/ delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { public void run() { sendNotificationAndFinish(); } }, MAXIMUM_CALL_NOTIFICATION_DURATION); } else if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { if (mPlayer == null) { mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.moments_30s); // mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { sendNotificationAndFinish(); } }); mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int i, int i2) { sendNotificationAndFinish(); return false; } }); mPlayer.start(); } } }
From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java
private int getAudioOutput() { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_RING"); if ("STREAM_VOICE_CALL".equals(value)) { return AudioManager.STREAM_VOICE_CALL; } else if ("STREAM_SYSTEM".equals(value)) { return AudioManager.STREAM_SYSTEM; } else if ("STREAM_RING".equals(value)) { return AudioManager.STREAM_RING; } else if ("STREAM_MUSIC".equals(value)) { return AudioManager.STREAM_MUSIC; } else if ("STREAM_ALARM".equals(value)) { return AudioManager.STREAM_ALARM; } else if ("STREAM_NOTIFICATION".equals(value)) { return AudioManager.STREAM_NOTIFICATION; } else if ("STREAM_DTMF".equals(value)) { return AudioManager.STREAM_DTMF; } else {/*from ww w . j a va2 s. co m*/ return AudioManager.STREAM_RING; } }
From source file:org.wso2.iot.agent.services.operation.OperationManager.java
/** * Mute the device.//from w ww . j a v a2s .c om * * @param operation - Operation object. */ public void muteDevice(org.wso2.iot.agent.beans.Operation operation) { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device muted"); } }
From source file:org.wso2.emm.agent.services.operation.OperationManager.java
/** * Mute the device./*from ww w. j a v a2s .c om*/ * * @param operation - Operation object. */ public void muteDevice(org.wso2.emm.agent.beans.Operation operation) { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device muted"); } }