List of usage examples for android.content Context AUDIO_SERVICE
String AUDIO_SERVICE
To view the source code for android.content Context AUDIO_SERVICE.
Click Source Link
From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java
/** * Decreases the Media Volume/*from ww w. j a v a 2s . c o m*/ * * @param context */ public static void decreaseMediaVolume(Context context) { // Get the AudioManager final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // Set the volume audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0); }
From source file:com.nick.scalpel.core.AutoFoundWirer.java
private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme, Field field, Object forWho) { Resources resources = context.getResources(); switch (type) { case STRING:/*from ww w . j a va2s .c o m*/ setField(field, forWho, resources.getString(idRes)); break; case COLOR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, resources.getColor(idRes, theme)); } else { //noinspection deprecation setField(field, forWho, resources.getColor(idRes)); } break; case INTEGER: setField(field, forWho, resources.getInteger(idRes)); break; case BOOL: setField(field, forWho, resources.getBoolean(idRes)); break; case STRING_ARRAY: setField(field, forWho, resources.getStringArray(idRes)); break; case INT_ARRAY: setField(field, forWho, resources.getIntArray(idRes)); break; case PM: setField(field, forWho, context.getSystemService(Context.POWER_SERVICE)); break; case ACCOUNT: setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE)); break; case ALARM: setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE)); break; case AM: setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE)); break; case WM: setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE)); break; case NM: setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE)); break; case TM: setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE)); break; case TCM: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE)); } break; case SP: setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context)); break; case PKM: setField(field, forWho, context.getPackageManager()); break; case HANDLE: setField(field, forWho, new Handler(Looper.getMainLooper())); break; case ASM: setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE)); break; case CAP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE)); } break; case KGD: setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE)); break; case LOCATION: setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE)); break; case SEARCH: setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE)); break; case SENSOR: setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE)); break; case STORAGE: setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE)); break; case WALLPAPER: setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE)); break; case VIBRATOR: setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE)); break; case CONNECT: setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE)); break; case NETWORK_STATUS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE)); } break; case WIFI: setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE)); break; case AUDIO: setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE)); break; case FP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE)); } break; case MEDIA_ROUTER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE)); } break; case SUB: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)); } break; case IME: setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE)); break; case CLIP_BOARD: setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE)); break; case APP_WIDGET: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE)); } break; case DEVICE_POLICY: setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE)); break; case DOWNLOAD: setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE)); break; case BATTERY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE)); } break; case NFC: setField(field, forWho, context.getSystemService(Context.NFC_SERVICE)); break; case DISPLAY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE)); } break; case USER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.USER_SERVICE)); } break; case APP_OPS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE)); } break; case BITMAP: setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null)); break; } }
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 ww w . j a v 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:com.intel.xdk.notification.Notification.java
public void beep(int count) { beepCount = (count > 0) ? count - 1 : 0; AudioManager mgr = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); final int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); soundPool.play(SOUND_BEEP, streamVolume, streamVolume, 1, beepCount, 1f); }
From source file:org.noise_planet.noisecapture.MeasurementService.java
@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();//w ww . j av a2 s.c om // 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 } }
From source file:nth.com.ares.utils.Utils.java
public static void playSound(Context context, int sound) { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float percent = 0.7f; int seventyVolume = (int) (maxVolume * percent); audio.setStreamVolume(AudioManager.STREAM_MUSIC, seventyVolume, 0); final MediaPlayer mp = MediaPlayer.create(context, sound); mp.start();/*from ww w . ja v a2 s .co m*/ }
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:net.gcompris.GComprisActivity.java
public static void abandonAudioFocus() { // Abandon audio focus Context mContext = m_instance.getApplicationContext(); AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); am.abandonAudioFocus(null);/*from ww w . j a va2 s .c o m*/ }
From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java
/** * Decreases the Media Volume only up to half of the device's max volume * /*from w w w . ja v a 2s.com*/ * @param context */ public static void safeDecreaseMediaVolume(Context context) { // Get the volume final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); final int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); final int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); final int minVolume = maxVolume / 2; Debug.d("currentVolume: " + currentVolume); Debug.d("maxVolume: " + maxVolume); Debug.d("minVolume: " + minVolume); if (currentVolume > minVolume) decreaseMediaVolume(context); }
From source file:com.smithdtyler.prettygoodmusicplayer.MusicPlaybackService.java
@Override public synchronized void onCreate() { Log.i(TAG, "Music Playback Service Created!"); isRunning = true;// w w w . j ava2s .c om sharedPref = PreferenceManager.getDefaultSharedPreferences(this); powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PGMPWakeLock"); random = new Random(); mp = new MediaPlayer(); mReadaheadThread = new ReadaheadThread(); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Log.i(TAG, "Song complete"); next(); } }); // https://developer.android.com/training/managing-audio/audio-focus.html audioFocusListener = new PrettyGoodAudioFocusChangeListener(); // Get permission to play audio am = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE); HandlerThread thread = new HandlerThread("ServiceStartArguments"); thread.start(); // Get the HandlerThread's Looper and use it for our Handler mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper); // https://stackoverflow.com/questions/19474116/the-constructor-notification-is-deprecated // https://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly/15538209#15538209 Intent resultIntent = new Intent(this, NowPlaying.class); resultIntent.putExtra("From_Notification", true); resultIntent.putExtra(AlbumList.ALBUM_NAME, album); resultIntent.putExtra(ArtistList.ARTIST_NAME, artist); resultIntent.putExtra(ArtistList.ARTIST_ABS_PATH_NAME, artistAbsPath); // Use the FLAG_ACTIVITY_CLEAR_TOP to prevent launching a second // NowPlaying if one already exists. resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0); Builder builder = new NotificationCompat.Builder(this.getApplicationContext()); String contentText = getResources().getString(R.string.ticker_text); if (songFile != null) { contentText = Utils.getPrettySongName(songFile); } Notification notification = builder.setContentText(contentText).setSmallIcon(R.drawable.ic_pgmp_launcher) .setWhen(System.currentTimeMillis()).setContentIntent(pendingIntent) .setContentTitle(getResources().getString(R.string.notification_title)).build(); startForeground(uniqueid, notification); timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { onTimerTick(); } }, 0, 500L); Log.i(TAG, "Registering event receiver"); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Apparently audio registration is persistent across lots of things... // restarts, installs, etc. mAudioManager.registerMediaButtonEventReceiver(cn); // I tried to register this in the manifest, but it doesn't seen to // accept it, so I'll do it this way. getApplicationContext().registerReceiver(receiver, filter); headphoneReceiver = new HeadphoneBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.HEADSET_PLUG"); registerReceiver(headphoneReceiver, filter); }