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:net.networksaremadeofstring.rhybudd.Notifications.java

public static void SendPollNotification(int EventCount, List<String> EventDetails, Context context) {
    Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Intent broadcastMassAck = new Intent();
    broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0);

    /*Intent broadcastIgnore = new Intent();
    broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this,0,broadcastIgnore,0);*/

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    Uri soundURI;/*from  w  w  w  .ja  va 2s.  c o  m*/
    int Flags = -1;
    String Event1 = "--", Event2 = "---";
    int remainingCount = 0;

    try {
        if (settings.getBoolean("notificationSound", true)) {
            if (settings.getString("notificationSoundChoice", "").equals("")) {
                soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            } else {
                try {
                    soundURI = Uri.parse(settings.getString("notificationSoundChoice", ""));
                } catch (Exception e) {
                    soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            }
        } else {
            soundURI = null;
        }
    } catch (Exception e) {
        soundURI = null;
    }

    try {
        if (EventDetails.size() > 1) {
            Event1 = EventDetails.get(0);
            Event2 = EventDetails.get(1);
            remainingCount = EventCount - 2;
        } else {
            Event1 = EventDetails.get(0);
            remainingCount = EventCount - 1;
        }
    } catch (Exception e) {

    }

    long[] vibrate = { 0, 100, 200, 300 };

    try {
        AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

        //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode()));
        switch (audio.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            //Do nothing to fix GitHub issue #13
            //Log.e("AudioManager","Doing nothing because we are silent");
            vibrate = new long[] { 0, 0 };
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat_alert)
                .setContentTitle(Integer.toString(EventCount) + " new Zenoss Events!")
                .setContentText("Tap to start Rhybudd").setContentIntent(contentIntent).setNumber(EventCount)
                .setSound(soundURI).setVibrate(vibrate).setAutoCancel(true).setOngoing(false)
                .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck)
                .setPriority(Notification.PRIORITY_HIGH);

        Notification notif = mBuilder.build();
        notif.tickerText = Integer.toString(EventCount) + " new Zenoss Events!";

        if (settings.getBoolean("notificationSoundInsistent", false))
            notif.flags |= Notification.FLAG_INSISTENT;

        NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNM.notify(NOTIFICATION_POLLED_ALERTS, notif);
    } catch (Exception e) {

    }
}

From source file:org.linphone.LinphoneService.java

@Override
public void onCreate() {
    super.onCreate();
    theLinphone = this;

    // Dump some debugging information to the logs
    Hacks.dumpDeviceInformation();//from  ww w.j  a v a2 s  .  c o  m
    addCallListner();
    //      tryTogetLastReceive();
    //      tryTogetLastRequest();
    tryKeepOnline();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis());
    mNotification.iconLevel = IC_LEVEL_ORANGE;
    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    Intent notificationIntent = new Intent(this, MainViewActivity.class);
    mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    try {
        copyAssetsFromPackage();

        mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC,
                LINPHONE_FACTORY_RC, null);

        mLinphoneCore.setPlaybackGain(3);
        mLinphoneCore.setRing(null);

        try {
            initFromConf();
        } catch (LinphoneException e) {
            Log.w(TAG, "no config ready yet");
        }
        TimerTask lTask = new TimerTask() {
            @Override
            public void run() {
                mLinphoneCore.iterate();
            }

        };

        mTimer.scheduleAtFixedRate(lTask, 0, 100);
        IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        lFilter.addAction(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mKeepAliveMgrReceiver, lFilter);

    } catch (Exception e) {
        Log.e(TAG, "Cannot start linphone", e);
    }

}

From source file:com.luhuiguo.cordova.voice.VoiceHandler.java

/**
 * Get the voice device to be used for playback.
 *
 * @return                  1=earpiece, 2=speaker
 *//*from  w w  w  . ja  va 2  s  .  c o  m*/
public int getVoiceOutputDevice() {
    AudioManager audiMgr = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
    if (audiMgr.isSpeakerphoneOn()) {
        return 2;
    } else {
        return 1;
    }
}

From source file:me.zhanghai.android.patternlock.PatternView.java

public PatternView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0);

    mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT);
    mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT);

    final String aspect = a.getString(R.styleable.PatternView_pl_aspect);

    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;//www. j a  va 2 s  .  c  o m
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }

    setClickable(true);

    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    // Removed since every developer should set their own patternViewStyle.
    //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
    //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
    //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor);

    a.recycle();

    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);

    mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);

    mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated);

    mPaint.setAntiAlias(true);
    mPaint.setDither(true);

    updatePatternSize();

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void vibrate(long miliseconds) {
    AudioManager audio = (AudioManager) BackendControllerImpl.getInstance().getFrontend().getContext()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audio.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
        Vibrator v = (Vibrator) BackendControllerImpl.getInstance().getFrontend().getContext()
                .getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(miliseconds);/*from  w  ww.  ja v a  2  s.c om*/
    }
}

From source file:org.easyaccess.phonedialer.CallingScreen.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_VOLUME_UP == event.getKeyCode()) {
        if (Utils.ringing == 1) {
            // announce the caller name/number
            announceCaller(this.callerDetails);
            return true;
        } else if (Utils.ringing == 0 && Utils.off_hook == 1) {
            // activate loudspeaker
            Utils.audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
            if (Utils.audioManager.isSpeakerphoneOn() == false) {
                Utils.audioManager.setSpeakerphoneOn(true);
            } else {
                // deactivate loudspeaker
                Utils.audioManager.setSpeakerphoneOn(false);
            }/*from  www  .  j a  va  2  s  .  c  o  m*/
            return true;
        }
    } else if (KeyEvent.KEYCODE_VOLUME_DOWN == event.getKeyCode()) {
        if (Utils.ringing == 1) {
            // mute the ringtone
            muteRingtone();
            return true;
        } else if (Utils.ringing == 0 && Utils.off_hook == 1) {

            if (Utils.audioManager.isMicrophoneMute() == true) {
                Utils.audioManager.setMicrophoneMute(false);
            } else {
                Utils.audioManager.setMicrophoneMute(true);
            }
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.skt.runtime.additionalapis.AudioHandler.java

/**
 * Get the audio device to be used for playback.
 *
 * @return               1=earpiece, 2=speaker
 *///from w  ww.  j av  a2  s .  c om
@SuppressWarnings("deprecation")
public int getAudioOutputDevice() {
    AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
    if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) {
        return 1;
    } else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) {
        return 2;
    } else {
        return -1;
    }
}

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);

    // Initialize instance variables.
    TextureView textureView = (TextureView) getActivity().findViewById(R.id.texture_view);
    textureView.setSurfaceTextureListener(this);

    setBackgroundType(BACKGROUND_TYPE);/*  w ww  .  ja  va  2s .  c om*/
    // Set up listener.
    setOnItemViewClickedListener(new ItemViewClickedListener());

}

From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java

@Override
protected void onDestroy() {
    Log.e(TAG, "on Destroy method");
    if (task != null) {
        task.cancel(true);//from  w ww  .  java 2  s.  co  m
    }
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, actualVolume, 0);
    if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.release();
    }
    if (vibrator != null) {
        vibrator.cancel();
    }
    NotificationManager alarmNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    alarmNotificationManager.cancelAll();
    if (flag) {
        int deleteAlarm = getIntent().getIntExtra(Constant.alarmDeleteAfterKey, 0);
        int id = getIntent().getIntExtra(Constant.alarmIdKey, -1);

        if (deleteAlarm == 1) {
            DataBaseManager dataBaseManager = DataBaseManager.getInstance(getApplicationContext());
            AlarmDataBase.deleteAlarm(id, dataBaseManager);
        } else if (getIntent().getStringExtra(Constant.alarmDaysKey).equals("0000000")) {
            DataBaseManager dataBaseManager = DataBaseManager.getInstance(getApplicationContext());
            Alarm alarm = AlarmDataBase.getAlarmById(dataBaseManager, id);
            alarm.setActivated(0);
            AlarmDataBase.updateAlarm(alarm, dataBaseManager);
        }
        AlarmReceiver.setAlarms(getApplicationContext());
    }
    super.onDestroy();
}

From source file:com.brejza.matt.habmodem.Dsp_service.java

public void startAudio() {
    if (!_enableDecoder)
        return;//from   www  .j a  v  a 2 s .c o  m

    boolean mic = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE);

    System.out.println("isRecording: " + isRecording);
    logEvent("Starting Audio. Mic avaliable: " + mic, false);
    if (!isRecording) {
        isRecording = true;

        buffsize = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT);
        buffsize = Math.max(buffsize, 3000);

        mRecorder = new AudioRecord(AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT, buffsize);

        mPlayer = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, 2 * buffsize, AudioTrack.MODE_STREAM);

        if (enableEcho) {
            AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            manager.setMode(AudioManager.MODE_IN_CALL);
            manager.setSpeakerphoneOn(true);
        }

        if (mRecorder.getState() != AudioRecord.STATE_INITIALIZED) {

            mRecorder = new AudioRecord(AudioSource.DEFAULT, 8000, AudioFormat.CHANNEL_IN_MONO,
                    AudioFormat.ENCODING_PCM_16BIT, buffsize);

            if (mRecorder.getState() != AudioRecord.STATE_INITIALIZED) {
                logEvent("Error - Could not initialise audio", true);
                return;
            }
            logEvent("Using default audio source", false);
        }

        mRecorder.startRecording();
        System.out.println("STARTING THREAD");
        Thread ct = new captureThread();
        logEvent("Starting Audio Thread.", false);
        setDecoderRunningNotification();
        ct.start();
    }
}