Example usage for android.media AudioManager EXTRA_RINGER_MODE

List of usage examples for android.media AudioManager EXTRA_RINGER_MODE

Introduction

In this page you can find the example usage for android.media AudioManager EXTRA_RINGER_MODE.

Prototype

String EXTRA_RINGER_MODE

To view the source code for android.media AudioManager EXTRA_RINGER_MODE.

Click Source Link

Document

The new ringer mode.

Usage

From source file:com.ayaseya.padnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;//from   w  w w . ja va 2s.com
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}

From source file:com.ayaseya.nolnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;/*w ww  . j  a va2 s. c o m*/
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);

        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            //            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            //            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}