Example usage for android.content Context AUDIO_SERVICE

List of usage examples for android.content Context AUDIO_SERVICE

Introduction

In this page you can find the example usage for android.content Context AUDIO_SERVICE.

Prototype

String AUDIO_SERVICE

To view the source code for android.content Context AUDIO_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.

Usage

From source file:com.z3r0byte.magis.Services.AutoSilentService.java

private void setup() {
    if (autoSilent) {
        TimerTask notificationTask = new TimerTask() {
            @Override//from   ww w  . jav a  2s  .  co  m
            public void run() {
                NotificationManager notificationManager = (NotificationManager) getApplicationContext()
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                        && !notificationManager.isNotificationPolicyAccessGranted()) {
                    Log.w(TAG, "run: Not allowed to change state of do not disturb!");
                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                            getApplicationContext());
                    mBuilder.setSmallIcon(R.drawable.magis512);

                    Intent resultIntent = new Intent(
                            android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
                    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
                    stackBuilder.addParentStack(CalendarActivity.class);
                    stackBuilder.addNextIntent(resultIntent);
                    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    mBuilder.setContentIntent(resultPendingIntent);

                    mBuilder.setContentTitle("Magis kan de telefoon niet op stil zetten");
                    mBuilder.setContentText("Klik om op te lossen");
                    mBuilder.setAutoCancel(true);
                    mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    mNotificationManager.notify(9999, mBuilder.build());
                    return;
                }
                appointments = calendarDB.getSilentAppointments(getMargin());
                if (doSilent(appointments)) {
                    silenced(true);
                    AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                    if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
                        audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    }
                } else {
                    if (isSilencedByApp()) {
                        AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                        audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                        silenced(false);
                    }
                }
            }
        };
        timer.schedule(notificationTask, 20000, 1000);
    }
}

From source file:nuclei.media.playback.FallbackPlayback.java

public FallbackPlayback(MediaService service) {
    mService = service;/*from   w ww .  j  av  a 2  s  .  c o m*/
    this.mAudioManager = (AudioManager) mService.getSystemService(Context.AUDIO_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    this.mWifiLock = ((WifiManager) mService.getApplicationContext().getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "uAmp_lock");
    this.mState = PlaybackStateCompat.STATE_NONE;
}

From source file:org.hansel.myAlert.ReminderService.java

private void playSound() {

    mMediaPlayer = new MediaPlayer();
    try {//from  w  w w  .  jav a  2  s  . co m
        mMediaPlayer.setDataSource(getApplicationContext(),
                Uri.parse(Util.getRingtone(getApplicationContext())));
        final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mMediaPlayer.prepare();
            mMediaPlayer.setLooping(true);
            mMediaPlayer.start();
        }
    } catch (IOException e) {
        System.out.println("Error tocando alarma");
    }
}

From source file:com.ssm.broadcast.GcmIntentService.java

private void sendNotification(String msg) {

    //msg? ?? ? ?? ? ? ?.

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DemoActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setTicker("PeopleTree").setContentTitle("PeopleTree")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            //.setWhen(System.currentTimeMillis())
            .setContentText(msg);//from  w  w w  .  ja v a 2 s.c  o m

    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    /* Even if the mode is set to "Sound & Vibration" in the phone, 
     * the status code that getRingerMode() returns is RINGER_MODE_NORMAL.
     */
    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        break;
    default:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:org.mitre.svmp.events.WebrtcHandler.java

public WebrtcHandler(BaseServer baseServer, VideoStreamInfo vidInfo, Context c) {
    base = baseServer;//from ww w  . j ava2 s .c o m
    context = c;
    // Pass in context to allow access to Android managed Audio driver.
    PeerConnectionFactory.initializeAndroidGlobals(context);
    //        "Failed to initializeAndroidGlobals");

    AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    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"));

    pcConstraints = constraintsFromJSON(vidInfo.getPcConstraints());
    Log.d(TAG, "pcConstraints: " + pcConstraints);

    videoConstraints = constraintsFromJSON(vidInfo.getVideoConstraints());
    Log.d(TAG, "videoConstraints: " + videoConstraints);
    //        
    //        videoConstraints = new MediaConstraints();
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minWidth","720"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minHeight","1280"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth","720"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight","1280"));
    //        videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minFrameRate","24"));

    audioConstraints = new MediaConstraints(); //null;
    audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("audio", "true"));

    iceServers = iceServersFromPCConfigJSON(vidInfo.getIceServers());
    onIceServers(iceServers);
}

From source file:re.serialout.MainScreen.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  w  w. j  av  a2 s  . c o m
    //Set up patient tracking
    dbhelper = new PatientDbHelper(this);
    //Set up communications
    AudioSerialOutMono.activate();
    AudioSerialOutMono.context = this.getApplicationContext();
    for (int rate : new int[] { 8000, 11025, 16000, 22050, 44100 }) {
        //Just here to make sure that the buffer types we are using are ok for the phone.
        //Debug thing.
        int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,
                AudioFormat.ENCODING_PCM_16BIT);
        if (bufferSize > 0) {
            System.out.println("Buffer size not 0 for rate: " + rate);
        }
    }
    am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    am.registerMediaButtonEventReceiver(new ComponentName(this, ButtonReciver.class));
    setUpFreqSlider();
    //        playSine.start();
    playSine.adjustFreq(14000);
    TextView pHoutput = (TextView) findViewById(R.id.instrText);
    //Check for pateint ID and log patient in
    commandInterface = new CommandInterface(buadRate, this.getApplicationContext(), pHoutput);
    if (savedInstanceState != null) {
        idSet = savedInstanceState.getBoolean("idSet");
        if (idSet) {
            idText = savedInstanceState.getString("idText");
            hideIDViews();
            settings = dbhelper.getSettings(Integer.parseInt(idText));
            if (settings.isFirstTime()) {
                Intent intent = new Intent(this, DemographicActivity.class);
                intent.putExtra("patientID", idText);
                startActivity(intent);
            }
            if (settings.isSurveyReady()) {
                (findViewById(R.id.startSurvey)).setVisibility(View.VISIBLE);
            }
        }
    }

    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
    clincMode = sharedPreferences.getBoolean("clincMode", false);
    if (!clincMode) {
        System.out.println("Not in clinic mode");
        idSet = sharedPreferences.getBoolean("idSet", false);
        if (idSet) {
            idText = sharedPreferences.getString("idText", "");
            System.out.println("id is: " + idText);
            hideIDViews();
        }
    }
    //        new checkForUpdates().execute();
}

From source file:com.perm.DoomPlay.PlayingService.java

@Override
public void onCreate() {
    super.onCreate();
    isLoadingTrack = false;/* w w w.ja  va  2s.co  m*/
    isShuffle = false;
    isPlaying = true;
    isLoop = false;

    afListener = new AFListener();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.requestAudioFocus(afListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    ComponentName componentName = new ComponentName(this, MediaButtonReceiver.class);
    audioManager.registerMediaButtonEventReceiver(componentName);

    ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(callListener,
            CallListener.LISTEN_CALL_STATE);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

    serviceAlive = true;
    bassPlayer = new BassPlayer();
    bassPlayer.setOnCompletetion(this);

}

From source file:rocks.stalin.android.app.playback.RemotePlayback.java

public RemotePlayback(Context context, MusicProvider musicProvider, OffsetSource timeProvider,
        TaskScheduler scheduler) {//from   ww w  .j a v  a 2  s  . co  m
    this.mContext = context;
    this.mMusicProvider = musicProvider;
    this.mAudioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    this.mWifiLock = ((WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "smus_lock");
    this.timeProvider = timeProvider;
    this.scheduler = scheduler;
    this.mState = PlaybackStateCompat.STATE_NONE;
}

From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java

@SuppressWarnings("deprecation")
public ProcessorVolumeStream(FeedbackController feedbackController, CursorController cursorController,
        DimScreenController dimScreenController, ScreenSpeakService service) {
    if (feedbackController == null)
        throw new IllegalStateException("CachedFeedbackController is null");
    if (cursorController == null)
        throw new IllegalStateException("CursorController is null");
    if (dimScreenController == null)
        throw new IllegalStateException("DimScreenController is null");

    mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
    mCursorController = cursorController;
    mFeedbackController = feedbackController;

    final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(service);
    mService = service;/*from w  ww.j a v  a 2  s  .c  o  m*/
    mDimScreenController = dimScreenController;
    mPatternDetector = new VolumeButtonPatternDetector();
    mPatternDetector.setOnPatternMatchListener(this);
}

From source file:org.hermes.android.NotificationsController.java

public NotificationsController() {
    notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);

    try {/*ww w .  java 2  s.  c  o  m*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
        //mediaPlayer = new MediaPlayer();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}