Example usage for android.media AudioManager RINGER_MODE_NORMAL

List of usage examples for android.media AudioManager RINGER_MODE_NORMAL

Introduction

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

Prototype

int RINGER_MODE_NORMAL

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

Click Source Link

Document

Ringer mode that may be audible and may vibrate.

Usage

From source file:Main.java

public static void setRingerMode(Context mContext, int x) {
    AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    switch (x) {/*  ww  w .ja v  a  2  s . com*/
    case 0:
        am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        break;
    case 1:
        am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        break;
    case 2:
        am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        break;
    /*case 3:
       am.setRingerMode(AudioManager.RINGER_MODE_);
       break;*/
    }
}

From source file:Main.java

public static void setRinger2Normal(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    //setting the volume
    audioManager.setStreamVolume(AudioManager.STREAM_RING, currentVolume, 0);
    Log.i("HelperFunctions ", "Normal method called");
}

From source file:com.intellisol.plugin.Ringer.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (NATIVE_ACTION_STRING.equals(action)) {
        int mode;
        try {//from  w ww .  j  a v a2 s.c o m
            // get mode from argument
            mode = args.getInt(0);

            // get context (Android)
            Context ctxt = cordova.getActivity().getBaseContext();
            if (mode == NORMAL) {
                // set ringer mode
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            } else if (mode == VIBRATE) {
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            } else if (mode == SILENT) {
                AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            }

        } catch (JSONException e) {
            // log error
            Log.d("Ringer", e.toString());
            return false;
        } catch (Exception e) {
            // log error
            Log.d("Ringer", e.toString());
            return false;
        }
    }
    return true;
}

From source file:com.kyakujin.android.autoeco.ui.SilentModeSettingFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mActivity = getActivity();//from   w  ww.  j a v a2 s.  co m
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.fragment_dialog_silentmode, null, false);
    RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroupSilentMode);

    // ?????????
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.radioNormal:
                mSilentMode = AudioManager.RINGER_MODE_NORMAL;
                break;
            case R.id.radioSilent:
                mSilentMode = AudioManager.RINGER_MODE_SILENT;
                break;
            case R.id.radioVibrate:
                mSilentMode = AudioManager.RINGER_MODE_VIBRATE;
                break;
            default:
            }
        }
    });

    mCurrentEcoId = getArguments().getInt(Conf.SHARED_ECOID);
    mSilentMode = getArguments().getInt(Conf.SHARED_SILENTMODE);

    switch (mSilentMode) {
    case AudioManager.RINGER_MODE_NORMAL:
        radioGroup.check(R.id.radioNormal);
        break;
    case AudioManager.RINGER_MODE_SILENT:
        radioGroup.check(R.id.radioSilent);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        radioGroup.check(R.id.radioVibrate);
        break;
    default:
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.setting_silent);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            EcoDAO dao = new EcoDAO(mActivity);
            dao.updateSilentMode(mCurrentEcoId, mSilentMode);
        }
    });
    builder.setNegativeButton("Cancel", null);
    builder.setView(view);

    return builder.create();

}

From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID));

    // Get notification title from Reminder Database
    ScheduleAutomuteDataSource scheduleAutomuteDataSource = new ScheduleAutomuteDataSource(context);
    scheduleAutomuteDataSource.open();//from   w  ww.ja v a 2  s. c om
    ScheduleAutomute scheduleAutomute = scheduleAutomuteDataSource.getScheduleAutomute(mReceivedID);
    mCalendar = Calendar.getInstance();

    myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    if (scheduleAutomute.getAutomuteMode().equals("Vibrate")) {
        myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    } else if (scheduleAutomute.getAutomuteMode().equals("Silent")) {
        myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    } else if (scheduleAutomute.getAutomuteMode().equals("Normal"))
        myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

}

From source file:com.prey.actions.picture.PictureUtil.java

private static byte[] getPicture(Context ctx, String focus) {
    AudioManager mgr = null;/* www.  jav a 2  s  .c  o  m*/
    SimpleCameraActivity.dataImagen = null;
    int streamType = AudioManager.STREAM_SYSTEM;
    SimpleCameraActivity.activity = null;
    Intent intent = new Intent(ctx, SimpleCameraActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("focus", focus);
    ctx.startActivity(intent);
    int i = 0;
    mgr = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    mgr.setStreamSolo(streamType, true);
    mgr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    mgr.setStreamMute(streamType, true);
    while (SimpleCameraActivity.activity == null && i < 10) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        i++;
    }
    if (SimpleCameraActivity.activity != null) {
        SimpleCameraActivity.activity.takePicture(ctx, focus);
    }
    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
    }
    mgr.setStreamSolo(streamType, false);
    mgr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    mgr.setStreamMute(streamType, false);
    try {
        i = 0;
        while (SimpleCameraActivity.activity != null && SimpleCameraActivity.dataImagen == null && i < 5) {
            Thread.sleep(2000);
            i++;
        }
    } catch (InterruptedException e) {
        PreyLogger.i("Error:" + e.getMessage());
    }
    byte[] out = null;
    if (SimpleCameraActivity.activity != null) {
        out = SimpleCameraActivity.dataImagen;
        SimpleCameraActivity.activity.finish();
        SimpleCameraActivity.activity = null;
        SimpleCameraActivity.dataImagen = null;

    }
    return out;
}

From source file:com.sublimis.urgentcallfilter.Magic.java

private void setRingerAudible() {
    if (mAudioManager != null)
        mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}

From source file:com.kaliturin.blacklist.utils.Notifications.java

private static void notify(Context context, String title, String message, String ticker, @DrawableRes int icon,
        String action, Uri ringtone, boolean vibration) {

    // turn off sound and vibration if phone is in silent mode
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        ringtone = null;//from w  w w. ja v a2 s  . c  o m
        vibration = false;
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        ringtone = null;
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        break;
    }

    // pending intent for activating app on click in status bar
    Intent intent = new Intent(context, MainActivity.class);
    intent.setAction(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    // build notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentIntent(pendingIntent);
    builder.setContentTitle(title);
    builder.setTicker(ticker);
    builder.setContentText(message);
    builder.setSmallIcon(icon);
    builder.setColor(getColor(context, R.attr.colorAccent));
    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    builder.setPriority(PRIORITY_MAX);
    builder.setAutoCancel(true);
    if (ringtone != null) {
        builder.setSound(ringtone);
    }
    if (vibration) {
        builder.setVibrate(new long[] { 0, 300, 300, 300 });
    }
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}

From source file:com.sublimis.urgentcallfilter.Magic.java

private boolean isRingerInRightMode() {
    boolean retVal = false;

    if (mAudioManager != null) {
        int ringerScope = MyPreference.getScope();

        switch (mRingerModeOriginal) {
        case AudioManager.RINGER_MODE_SILENT:
            if ((ringerScope & 1) != 0)
                retVal = true;//  w  ww.j av  a 2s.  c  o  m
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            if ((ringerScope & 2) != 0)
                retVal = true;
            break;
        case AudioManager.RINGER_MODE_NORMAL:
            if ((ringerScope & 4) != 0) {
                if (mVolumeOriginal < mVolumeMax)
                    retVal = true;
            }
            break;
        }
    }

    return retVal;
}

From source file:tm.android.chronos.services.TimerRunner.java

private void prepareSound() {
    playSound = false;/*from   w  w  w . j ava 2s .c o  m*/
    if (Permissions.Instance().hasReadWriteExternalStorage(context)) {
        Couple<Boolean, Integer> result = Permissions.Instance().checkZenModeAccess(context);
        if (result.getValue() == AudioManager.RINGER_MODE_NORMAL
                || (result.getValue() != AudioManager.RINGER_MODE_NORMAL) && result.getKey()) {
            playSound = true;
        }
    }
    if (playSound) {
        audioProperties = new AudioProperties();
        audioProperties.loadFromPref(PreferenceCst.PREFIX_TIMER, context);
        CommonMediaPlayer.build(context);
    }
}