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:Main.java

/**
 * Getter for the current Default Notification Ringtone URI.
 * @param ctx//  w  w  w .  j a  v a 2s . c o m
 * @return
 */
public static Uri getDefaultNotificationRingtoneUri(Context ctx) {
    return RingtoneManager.getActualDefaultRingtoneUri(ctx, RingtoneManager.TYPE_NOTIFICATION);
}

From source file:Main.java

/**
 * Return true if the system has a system default ringtone. This is always
 * false for most tablets./*from  ww w.  j  a  v a 2 s  . com*/
 *
 * @param ctx the {@link Context}
 * @return true or false
 */
public static boolean hasSystemDefaultRingtone(Context ctx, int type) {
    return RingtoneManager.getActualDefaultRingtoneUri(ctx, type) != null;
}

From source file:Main.java

/**
 * Returns the system default ringtone URI {@link Uri}, or
 * the first available ringtone when the system default
 * does not exist (usually tablets)./*w  w w  . j  a  v  a 2s  .c  o  m*/
 *
 * @param ctx the {@link Context}
 * @return Uri ringtone URI
 */
public static Uri getDefaultRingtoneUri(Context ctx, int type) {
    Uri uri;

    uri = RingtoneManager.getActualDefaultRingtoneUri(ctx, type);

    if (uri == null) {
        // The default ringtone doesn't exist - probably a tablet
        // Return the first available
        RingtoneManager rm = new RingtoneManager(ctx);
        rm.setType(type);

        Cursor cursor = rm.getCursor();
        cursor.moveToFirst();

        String idString = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
        String uriString = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        uri = Uri.parse(uriString + '/' + idString);

        cursor.close();

        return uri;
    } else {
        // Return system default ringtone
        return uri;
    }
}

From source file:Main.java

private static Uri getDefaultRingtoneUri(Context context, int type) {
    return RingtoneManager.getActualDefaultRingtoneUri(context, type);
}

From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java

public static int createScheduleNotification(Context context, Schedule s) {
    Log.w("UTILS", "createScheduleNotification()");
    ScheduleDataSource dataSource;/*from w  w  w  . j  a va 2s.c  om*/

    dataSource = new ScheduleDataSource(context);
    dataSource.open();
    //  Random r = new Random();
    int mId = 0;// r.nextInt();
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String uri = s.getRingtone(); // prefs.getString("pref_general_sound_key", "");
    Uri ringtone = Uri.parse(uri);
    if (uri == "") { // isEmpty() is not available on API 7
        ringtone = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION);
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getResources().getString(R.string.app_name))
            .setContentText(context.getResources().getString(R.string.notification));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mBuilder.setSound(ringtone);
    //mBuilder.setWhen(s.getDate());
    mNotificationManager.notify(mId, mBuilder.build());
    s.setIsEnabled(false);
    dataSource.updateSchedule(context, s);
    dataSource.close();
    return mId;
}

From source file:org.wso2.iot.agent.AlertActivity.java

/**
 * This method is used to start ringing the phone.
 *//*from w w  w . ja v a2  s . c  om*/
@TargetApi(21)
private void startRing() {
    if (audio != null) {
        ringerMode = audio.getRingerMode();
        ringerVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
        audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING),
                AudioManager.FLAG_PLAY_SOUND);

        defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

        if (defaultRingtoneUri != null) {
            defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri);

            if (defaultRingtone != null) {
                if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) {
                    AudioAttributes attributes = new AudioAttributes.Builder()
                            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
                    defaultRingtone.setAudioAttributes(attributes);
                } else {
                    defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
                }
                defaultRingtone.play();
            }
        }
    }
}

From source file:org.wso2.emm.agent.AlertActivity.java

/**
 * This method is used to start ringing the phone.
 *///  ww w  . j av a2  s  .c  o m
@TargetApi(21)
private void startRing() {
    if (audio != null) {
        audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING),
                AudioManager.FLAG_PLAY_SOUND);

        defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

        if (defaultRingtoneUri != null) {
            defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri);

            if (defaultRingtone != null) {
                if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) {
                    AudioAttributes attributes = new AudioAttributes.Builder()
                            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
                    defaultRingtone.setAudioAttributes(attributes);
                } else {
                    defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
                }
                defaultRingtone.play();
            }
        }
    }
}

From source file:de.j4velin.chess.Main.java

@Override
public void onTurnBasedMatchReceived(final TurnBasedMatch match) {
    if (BuildConfig.DEBUG)
        Logger.log("Main onTurnBasedMatchReceived: " + match.getMatchId());
    if (match.getTurnStatus() == TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN
            && match.getStatus() == TurnBasedMatch.MATCH_STATUS_ACTIVE) {
        final Ringtone tone = RingtoneManager.getRingtone(this,
                RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION));
        tone.setStreamType(AudioManager.STREAM_NOTIFICATION);
        tone.play();//from   w ww .  j a v a2s. c om
    }
    if (startFragment != null && startFragment.isVisible()) {
        startFragment.loadMatches();
    }
    if (gameFragment != null && gameFragment.isVisible()
            && match.getMatchId().equals(gameFragment.currentMatch)) {
        if (Game.load(match.getData(), match, mGoogleApiClient)) {
            gameFragment.update(match.getStatus() != TurnBasedMatch.MATCH_STATUS_ACTIVE
                    && match.getStatus() != TurnBasedMatch.MATCH_STATUS_AUTO_MATCHING);
        } else {
            updateApp();
        }
    }
}

From source file:com.stasbar.knowyourself.DeskClock.java

private boolean isSystemAlarmRingtoneSilent() {
    return RingtoneManager.getActualDefaultRingtoneUri(this, TYPE_ALARM) == null;
}

From source file:com.finchuk.clock2.alarms.ui.ExpandedAlarmViewHolder.java

private Uri getSelectedRingtoneUri() {
    // If showing an item for "Default" (@see EXTRA_RINGTONE_SHOW_DEFAULT), this can be one
    // of DEFAULT_RINGTONE_URI, DEFAULT_NOTIFICATION_URI, or DEFAULT_ALARM_ALERT_URI to have the
    // "Default" item checked.
    ///*from w  ww. j  av a2s  . c o m*/
    // Otherwise, use RingtoneManager.getActualDefaultRingtoneUri() to get the "actual sound URI".
    //
    // Do not use RingtoneManager.getDefaultUri(), because that just returns one of
    // DEFAULT_RINGTONE_URI, DEFAULT_NOTIFICATION_URI, or DEFAULT_ALARM_ALERT_URI
    // depending on the type requested (i.e. what the docs calls "symbolic URI
    // which will resolved to the actual sound when played").
    String ringtone = getAlarm().ringtone();
    return ringtone.isEmpty()
            ? RingtoneManager.getActualDefaultRingtoneUri(getContext(), RingtoneManager.TYPE_ALARM)
            : Uri.parse(ringtone);
}