Example usage for android.media RingtoneManager getActualDefaultRingtoneUri

List of usage examples for android.media RingtoneManager getActualDefaultRingtoneUri

Introduction

In this page you can find the example usage for android.media RingtoneManager getActualDefaultRingtoneUri.

Prototype

public static Uri getActualDefaultRingtoneUri(Context context, int type) 

Source Link

Document

Gets the current default sound's Uri .

Usage

From source file:com.lambdasoup.quickfit.alarm.AlarmService.java

@WorkerThread
private void refreshNotificationDisplay() {
    try (Cursor toNotify = getContentResolver().query(QuickFitContentProvider.getUriWorkoutsList(),
            new String[] { WorkoutEntry.SCHEDULE_ID, WorkoutEntry.WORKOUT_ID, WorkoutEntry.ACTIVITY_TYPE,
                    WorkoutEntry.LABEL, WorkoutEntry.DURATION_MINUTES },
            ScheduleEntry.TABLE_NAME + "." + ScheduleEntry.COL_SHOW_NOTIFICATION + "=?",
            new String[] { Integer.toString(ScheduleEntry.SHOW_NOTIFICATION_YES) }, null)) {
        int count = toNotify == null ? 0 : toNotify.getCount();
        if (count == 0) {
            Timber.d("refreshNotificationDisplay: no events");
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    NOTIFICATION_SERVICE);
            notificationManager.cancel(Constants.NOTIFICATION_ALARM);
            return;
        }/*from   ww  w .  j  av a2 s . c o m*/

        long[] scheduleIds = new long[count];
        int i = 0;
        toNotify.moveToPosition(-1);
        while (toNotify.moveToNext()) {
            scheduleIds[i] = toNotify.getLong(toNotify.getColumnIndex(WorkoutEntry.SCHEDULE_ID));
            i++;
        }

        PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 0,
                getIntentOnNotificationsCanceled(this, scheduleIds), PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder notification;
        if (count == 1) {
            Timber.d("refreshNotificationDisplay: single event");
            toNotify.moveToFirst();
            notification = notifySingleEvent(toNotify, cancelIntent);
        } else {
            Timber.d("refreshNotificationDisplay: multiple events");
            toNotify.moveToPosition(-1);
            notification = notifyMultipleEvents(toNotify, cancelIntent);
        }

        notification.setDeleteIntent(cancelIntent);
        notification.setAutoCancel(true);
        notification.setPriority(Notification.PRIORITY_HIGH);
        notification.setSmallIcon(R.drawable.ic_stat_quickfit_icon);
        notification.setColor(ContextCompat.getColor(this, R.color.colorPrimary));

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        String ringtoneUriStr = preferences.getString(getString(R.string.pref_key_notification_ringtone), null);
        if (ringtoneUriStr == null) {
            notification.setSound(
                    RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION));
        } else if (!ringtoneUriStr.isEmpty()) {
            notification.setSound(Uri.parse(ringtoneUriStr));
        }
        boolean ledOn = preferences.getBoolean(getString(R.string.pref_key_notification_led), true);
        boolean vibrationOn = preferences.getBoolean(getString(R.string.pref_key_notification_vibrate), true);
        notification.setDefaults(
                (ledOn ? Notification.DEFAULT_LIGHTS : 0) | (vibrationOn ? Notification.DEFAULT_VIBRATE : 0));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            notification.setCategory(Notification.CATEGORY_ALARM);
        }

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(Constants.NOTIFICATION_ALARM, notification.build());
    }
}

From source file:com.embeddedlog.LightUpDroid.LightUpPiSync.java

private Alarm alarmFromJson(JSONObject aJson) {
    // If mSelectedAlarm is null then we're creating a new alarm.
    Alarm alarm = new Alarm();
    alarm.alert = RingtoneManager.getActualDefaultRingtoneUri(mActivityContext, RingtoneManager.TYPE_ALARM);
    if (alarm.alert == null) {
        alarm.alert = Uri.parse("content://settings/system/alarm_alert");
    }//from www.j  a  v a2  s.co  m
    // Setting the vibrate option to always true, as there is no attribute in LightUpPi
    alarm.vibrate = true;
    // Setting the 'delete after use' option to always false, as there is no such feature in
    // the LightUpPi alarm system and all alarms are repeatable
    alarm.deleteAfterUse = false;

    // Parsing the JSON data
    try {
        alarm.hour = aJson.getInt("hour");
        alarm.minutes = aJson.getInt("minute");
        alarm.enabled = aJson.getBoolean("enabled");
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("monday"), Calendar.MONDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("tuesday"), Calendar.TUESDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("wednesday"), Calendar.WEDNESDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("thursday"), Calendar.THURSDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("friday"), Calendar.FRIDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("saturday"), Calendar.SATURDAY);
        alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("sunday"), Calendar.SUNDAY);
        alarm.label = aJson.getString("label");
        alarm.lightuppiId = aJson.getLong("id");
        alarm.timestamp = aJson.getLong("timestamp");
    } catch (JSONException e) {
        Log.w(LOG_TAG + " JSONException: " + e.toString());
        alarm = null;
    }
    return alarm;
}

From source file:com.android.deskclock.AlarmClockFragment.java

private Uri getDefaultRingtoneUri() {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final String ringtoneUriString = sp.getString(PREF_KEY_DEFAULT_ALARM_RINGTONE_URI, null);

    final Uri ringtoneUri;
    if (ringtoneUriString != null) {
        ringtoneUri = Uri.parse(ringtoneUriString);
    } else {/*from w  w w  . ja  v  a  2s  . c  om*/
        ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_ALARM);
    }

    return ringtoneUri;
}

From source file:com.android.deskclock.AlarmClockFragment.java

/**
 * M: Set the system default Alarm Ringtone,
 * then save it as the Clock internal used ringtone.
 *///from  ww  w. j  a  va2  s  .co m
public void setSystemAlarmRingtoneToPref() {
    Uri systemDefaultRingtone = RingtoneManager.getActualDefaultRingtoneUri(getActivity(),
            RingtoneManager.TYPE_ALARM);
    /// M: The RingtoneManager may return null alert. @{
    if (systemDefaultRingtone == null) {
        systemDefaultRingtone = Uri.parse(SYSTEM_SETTINGS_ALARM_ALERT);
    }
    /// @}
    setDefaultRingtone(systemDefaultRingtone.toString());
    LogUtils.v("setSystemAlarmRingtone: " + systemDefaultRingtone);
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean playBackDefaultAlarm(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse tr, ActionResponse ar) {
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return false;
    }// www  .  j a  v  a  2  s. c  om
    Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_ALARM);
    //      Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (uri != null) {
        playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id,
                PROFILE_ACTION_RINGTONE_TYPE_ALARM, "", uri.getEncodedPath(), "-1", "-1");
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "Default alarm does not exists";
    }
    return true;
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean playBackDefaultNotification(TaskManagerParms taskMgrParms,
        EnvironmentParms envParms, CommonUtilities util, TaskResponse tr, ActionResponse ar) {
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return false;
    }//from   w  w w .ja v a2s .  c o  m
    Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context,
            RingtoneManager.TYPE_NOTIFICATION);
    //      Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id,
                PROFILE_ACTION_RINGTONE_TYPE_NOTIFICATION, "", uri.getEncodedPath(), "-1", "-1");
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "Default notification does not exists";
    }

    return true;
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean playBackDefaultRingtone(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse tr, ActionResponse ar) {
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return false;
    }/*from   w  ww.j  a  va 2  s .c  o m*/
    Uri uri = RingtoneManager.getActualDefaultRingtoneUri(taskMgrParms.context, RingtoneManager.TYPE_RINGTONE);
    //      Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    if (uri != null) {
        playBackRingtone(taskMgrParms, envParms, util, tr, ar, tr.active_dialog_id,
                PROFILE_ACTION_RINGTONE_TYPE_RINGTONE, "", uri.getEncodedPath(), "-1", "-1");
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "Default ringtone does not exists";
    }
    return true;
}