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.globide.coloring_book_08.MainActivity.java

/**
 * private RelativeLayout mRlMainRight; private RelativeLayout mRlMainLeft;
 * Implements onCreate()./* w  w  w . j a v a  2s. c  o m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the activity to full screen mode.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Add default content.
    setContentView(R.layout.activity_main);

    // Determine whether or not the current device is a tablet.
    MainActivity.sIsTablet = getResources().getBoolean(R.bool.isTablet);
    MainActivity.sIsSmall = getResources().getBoolean(R.bool.isSmall);
    MainActivity.sIsNormal = getResources().getBoolean(R.bool.isNormal);
    MainActivity.sIsLarge = getResources().getBoolean(R.bool.isLarge);
    MainActivity.sIsExtraLarge = getResources().getBoolean(R.bool.isExtraLarge);

    // Get stored preferences, if any.
    mSharedPreferences = getSharedPreferences(sFilename, 0);
    // Setup the editor in this function, so it can be used anywhere else if
    // needed.
    mEditor = mSharedPreferences.edit();

    // If this activity continues playing the music, start the media player
    // if the phone is not muted
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // This should only run once at the start of the application.
    switch (audio.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        if (!MusicManager.sIsManualSound) {
            // Set the preferences to turn music off.
            mEditor.putBoolean("tbSettingsMusicIsChecked", false);
            mEditor.commit();
        }
        break;
    }

    // This should only run once at the start of the application.
    if (!MusicManager.sIsManualSound) {
        // Set the preferences as early as possible in MusicManager.
        MusicManager.setPreferences(mSharedPreferences);

        // Update actual status
        MusicManager.updateVolume();
        MusicManager.updateStatusFromPrefs(this);

        // This method can no longer be invoked to turn off the
        // sound once the user has manually turned sound on.
        MusicManager.sIsManualSound = true;
    }

    // Store the preference values in local variables.
    boolean tbSettingsMusicIsChecked = mSharedPreferences.getBoolean("tbSettingsMusicIsChecked", false);

    // Set whether music is on or not in the Music Manager
    if (tbSettingsMusicIsChecked) {
        MusicManager.start(this, MusicManager.MUSIC_A);
    }

    // Attach views to their corresponding resource ids.
    mIbPagerLeft = (ImageButton) findViewById(R.id.ibPagerLeft);
    mIbPagerRight = (ImageButton) findViewById(R.id.ibPagerRight);
    mIbMainHelp = (ImageButton) findViewById(R.id.ibMainHelp);
    mIbMainSettings = (ImageButton) findViewById(R.id.ibMainSettings);
    mRlMainLeftTop = (RelativeLayout) findViewById(R.id.rlMainLeftTop);
    mRlMainRightTop = (RelativeLayout) findViewById(R.id.rlMainRightTop);

    /*
     * This screen needs to be dynamically positioned to fit each screen
     * size fluidly.
     */

    // Get the screen metrics.
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenHeight = dm.heightPixels;

    // Determine the floor section size
    Drawable image = this.getResources().getDrawable(R.drawable.floor);
    // Store the height locally
    int floorHeight = image.getIntrinsicHeight();

    // Determine the title section size

    // Get the top spacing (THIS IS ALSO DEFINED EXACTLY AS IT IS HERE IN
    // EACH XML FILE.
    int topSpacing = 0;

    if (MainActivity.sIsTablet) {
        if (MainActivity.sIsSmall) {
            topSpacing = 18;
        } else if (MainActivity.sIsNormal) {
            topSpacing = 24;
        } else if (MainActivity.sIsLarge) {
            topSpacing = 27;
        } else if (MainActivity.sIsExtraLarge) {
            topSpacing = 30;
        }
    } else {
        topSpacing = 12;
    }

    Drawable imageTitle = this.getResources().getDrawable(R.drawable.main_title);
    // Store the height locally
    int titleHeight = imageTitle.getIntrinsicHeight() + topSpacing;

    // Resize the layout views to be centered in their proper positions
    // based on the sizes calculated.
    ViewGroup.LayoutParams paramsLeftTop = mRlMainLeftTop.getLayoutParams();
    ViewGroup.LayoutParams paramsRightTop = mRlMainRightTop.getLayoutParams();
    int resultHeight = (screenHeight - floorHeight) - titleHeight;
    paramsLeftTop.height = resultHeight;
    paramsRightTop.height = resultHeight;
    mRlMainLeftTop.setLayoutParams(paramsLeftTop);
    mRlMainRightTop.setLayoutParams(paramsRightTop);

    // TODO: See if there are better methods of retrieving the floor height
    // value from the xml layout.

    // Set listeners to objects that can receive user input.
    mIbPagerRight.setOnClickListener(this);
    mIbPagerLeft.setOnClickListener(this);
    mIbMainHelp.setOnClickListener(this);
    mIbMainSettings.setOnClickListener(this);

    // Database check!

    // Create our database access object.
    mDbNodeHelper = new NodeDatabase(this);

    // Call the create method right just in case the user has never run the
    // app before. If a database does not exist, the prepopulated one will
    // be copied from the assets folder. Else, a connection is established.
    mDbNodeHelper.createDatabase();

    // Query the database for all purchased categories.

    // Set a conditional buffer. Internally, the orderby is set to _id ASC
    // (NodeDatabase.java).
    mDbNodeHelper.setConditions("isAvailable", "1");
    // Execute the query.
    mCategoryData = mDbNodeHelper.getCategoryListData();
    // Store the number of categories available.
    mCategoryLength = mCategoryData.length;
    // Flush the buffer.
    mDbNodeHelper.flushQuery();

    // This activity no longer needs the connection, so close it.
    mDbNodeHelper.close();

    // Initialize the pager
    this.initializePaging();
}

From source file:u.ready_wisc.MenuActivity.java

@Override
public void onClick(View v) {
    //TODO fix action bar or disable completely
    if ((v.getId() == (R.id.prepareButton)) || (v.getId() == (R.id.prepareMenuButton))) {
        Intent i = new Intent(MenuActivity.this, Prep_Main.class);
        startActivity(i);/*from   w  w  w.j  a v a2  s  . c o m*/
    } else if (v.getId() == (R.id.reportDamageButton) || v.getId() == (R.id.emergencyMenuButton)) {
        Intent i = new Intent(MenuActivity.this, Emergency.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.disasterResourcesButton) || v.getId() == (R.id.disasterMenuButton)) {
        Intent i = new Intent(MenuActivity.this, ResourcesActivity.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.typeDisasterButton)) {
        Intent i = new Intent(MenuActivity.this, DisastersType.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.SOSMenubutton)) {
        if (!sosTone) {

            //sets device volume to maximum
            AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);

            //begins looping tone
            mp.setLooping(true);
            sosTone = true;
            mp.start();
        }

    } else if (v.getId() == (R.id.FlashlightMenuButton)) {
        //check to see if device has a camera with flash
        if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {

            Log.e("err", "Device has no camera!");
            //Return from the method, do nothing after this code block
            return;
        }
        // if camera has flash toggle on and off
        else {
            // boolean to check status of camera flash
            if (!isFlashOn) {

                //if flash is off, toggle boolean to on and turn on flash
                isFlashOn = true;
                camera = Camera.open();
                Camera.Parameters parameters = camera.getParameters();
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                camera.setParameters(parameters);
                camera.startPreview();

            } else {

                //if flash is on turn boolean to false and turn off flash
                isFlashOn = false;
                camera.stopPreview();
                camera.release();
                camera = null;

            }
        }
    } else {

        //stops looping sound
        Log.d("Sound test", "Stopping sound");
        mp.setLooping(false);
        mp.pause();
        sosTone = false;
    }
}

From source file:com.godowondev.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w w  w. jav a2 s.  com*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    if (message.startsWith("[ADDITIONAL_MAIL_RING")) {
        intent.putExtra("navi_type", "additional_mail");
        //defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wakeup);

        //sendSMS("01099989584", message);
    } else {
        intent.putExtra("navi_type", "reservation_error");
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo).setContentTitle("?? PUSH ").setContentText(message)
            .setAutoCancel(true).setContentIntent(pendingIntent);

    if (message.startsWith("[ADDITIONAL_MAIL_SMS")) {
        //notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
        notificationBuilder.setSound(defaultSoundUri);
    } else if (message.startsWith("[ADDITIONAL_MAIL_RING")) {
        AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        notificationBuilder.setSound(defaultSoundUri);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Notification note = notificationBuilder.build();

    if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KYS]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_KYS]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]"))
            && getResources().getString(R.string.member_name).equals("?")) {
        notificationManager.notify(0 /* ID of notification */, note);
    }

    if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KDW]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_KDW]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]"))
            && getResources().getString(R.string.member_name).equals("")) {
        notificationManager.notify(0 /* ID of notification */, note);
    }
    //note.flags = Notification.FLAG_INSISTENT; // ?  ? 
    //notificationManager.notify(0 /* ID of notification */, note);
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

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

    try {//w  w w. ja  va  2 s  . c om
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("tmessages", "delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    };
}

From source file:com.ece420.lab3.MainActivity.java

private void queryNativeAudioParameters() {
    AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    nativeSampleRate = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
    nativeSampleBufSize = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
    int recBufSize = AudioRecord.getMinBufferSize(Integer.parseInt(nativeSampleRate),
            AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
    supportRecording = true;//w w w. jav  a2 s  .  c  o  m
    if (recBufSize == AudioRecord.ERROR || recBufSize == AudioRecord.ERROR_BAD_VALUE) {
        supportRecording = false;
    }
}

From source file:com.b44t.messenger.NotificationsController.java

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

    try {/*  w w w  .j a v a 2s  . co m*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("messenger", "delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e("messenger", e);
            }
        }
    };
}

From source file:goo.TeaTimer.TimerActivity.java

/** Called when the activity is first created.
  *   { @inheritDoc} /*from   w ww .j  ava  2s .com*/
  */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mCancelButton = (ImageButton) findViewById(R.id.cancelButton);
    mCancelButton.setOnClickListener(this);

    mSetButton = (Button) findViewById(R.id.setButton);
    mSetButton.setOnClickListener(this);

    mPauseButton = (ImageButton) findViewById(R.id.pauseButton);
    mPauseButton.setOnClickListener(this);

    mPauseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pause);

    mPlayBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.play);

    mTimerLabel = (TextView) findViewById(R.id.label);

    mTimerAnimation = (TimerAnimation) findViewById(R.id.imageView);

    enterState(STOPPED);

    // Store some useful values
    mSettings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    mAlarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mSettings.registerOnSharedPreferenceChangeListener(this);

}

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

public ExoPlayerPlayback(MediaService service) {
    mService = service;//  w  w w . j  a va 2s .  co m
    mHandler = new Handler();
    final Context ctx = service.getApplicationContext();
    mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    PowerManager powerManager = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "nuclei_media_wifi_lock");
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nuclei_media_cpu_lock");
}

From source file:org.durka.hallmonitor.CoreStateManager.java

CoreStateManager(Context context) {
    mAppContext = context;/* w  w  w  .  j av a2  s.c  o m*/
    mPowerManager = (PowerManager) mAppContext.getSystemService(Context.POWER_SERVICE);
    daPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreStateManager");
    daPartialWakeLock.setReferenceCounted(false);
    globalPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver");
    globalPartialWakeLock.setReferenceCounted(true);

    preference_all = PreferenceManager.getDefaultSharedPreferences(mAppContext);

    // Enable access to sleep mode
    systemApp = (mAppContext.getApplicationInfo().flags
            & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    if (systemApp) {
        Log.d(LOG_TAG, "We are a system app.");
    } else {
        Log.d(LOG_TAG, "We are not a system app.");
        preference_all.edit().putBoolean("pref_internal_power_management", false).commit();
    }

    refreshAdminApp();
    refreshRootApp();

    refreshLockMode();
    refreshOsPowerManagement();
    refreshInternalPowerManagement();

    refreshInternalService();

    if (preference_all.getBoolean("pref_proximity", false)) {
        forceCheckCoverState = true;
    }

    hmAppWidgetManager = new HMAppWidgetManager(this);

    if (preference_all.getBoolean("pref_default_widget", false)) {
        int widgetId = preference_all.getInt("default_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("default");
        } else {
            createWidget("default");
        }
    }

    if (preference_all.getBoolean("pref_media_widget", false)) {
        audioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

        int widgetId = preference_all.getInt("media_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("media");
        } else {
            createWidget("media");
        }
    }

    this.hardwareAccelerated = preference_all.getBoolean("pref_hardwareAccelerated", false);

    // we might have missed a phone-state revelation
    phone_ringing = ((TelephonyManager) mAppContext.getSystemService(Context.TELEPHONY_SERVICE))
            .getCallState() == TelephonyManager.CALL_STATE_RINGING;
    // we might have missed an alarm alert
    // TODO: find a way
    // alarm_firing =
    // ((TelephonyManager)
    // mAppContext.getSystemService(Context.TELEPHONY_SERVICE)).getCallState()
    // == TelephonyManager.CALL_STATE_RINGING;
    Intent stateIntent = mAppContext.registerReceiver(null, new IntentFilter(CoreReceiver.TORCH_STATE_CHANGED));
    torch_on = stateIntent != null && stateIntent.getIntExtra("state", 0) != 0;

    init = true;
}

From source file:com.ferdi2005.secondgram.NotificationsController.java

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

    try {/*from  w  w w.java 2 s .c om*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e(e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e(e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e(e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    };
}