Example usage for android.media RingtoneManager TYPE_RINGTONE

List of usage examples for android.media RingtoneManager TYPE_RINGTONE

Introduction

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

Prototype

int TYPE_RINGTONE

To view the source code for android.media RingtoneManager TYPE_RINGTONE.

Click Source Link

Document

Type that refers to sounds that are used for the phone ringer.

Usage

From source file:Main.java

public static Uri getDefaultRingtoneUri(Context ctx) {
    return getDefaultRingtoneUri(ctx, RingtoneManager.TYPE_RINGTONE);
}

From source file:Main.java

/**
 * Get an alarm sound. Try for an alarm. If none set, try notification, otherwise, ringtone.
 *
 * @return Alarm media uri//from w ww.ja  va  2s  . co m
 */
private static Uri getAlarmUri() {
    Uri alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (alarm == null) {
        alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alarm == null) {
            alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        }
    }
    return alarm;
}

From source file:org.mariotaku.twidere.preference.RingtonePreference.java

public RingtonePreference(final Context context, final AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RingtonePreference);
    mRingtoneType = a.getInt(R.styleable.RingtonePreference_android_ringtoneType,
            RingtoneManager.TYPE_RINGTONE);
    mShowDefault = a.getBoolean(R.styleable.RingtonePreference_android_showDefault, true);
    mShowSilent = a.getBoolean(R.styleable.RingtonePreference_android_showSilent, true);
    a.recycle();//www  .j  av  a2  s .c  om
}

From source file:com.vncreatures.customItems.wakefulservice.AppService.java

private void updateNotification() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String userId = pref.getString(Common.USER_ID, null);
    HrmService service = new HrmService();
    if (userId != null) {
        service.requestGetNotification(userId);
        service.setCallback(new ThreadTaskCallback() {

            @Override// w  w w. ja  va2 s  . c om
            public void onSuccess(ThreadModel threadModel) {
                int count = threadModel.countAllNotification();
                if (count > 0) {
                    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    if (alarmSound == null) {
                        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
                        if (alarmSound == null) {
                            alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
                        }
                    }

                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                            getApplicationContext()).setSmallIcon(R.drawable.vnc_icon)
                                    .setContentTitle(getString(R.string.app_name))
                                    .setContentText(getString(R.string.notification_overall, count))
                                    .setSound(alarmSound).setAutoCancel(true);
                    // Creates an explicit intent for an Activity in your
                    // app
                    Intent resultIntent = new Intent(getApplicationContext(), LoginActivity.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(getApplicationContext());
                    // Adds the back stack for the Intent (but not the
                    // Intent
                    // itself)
                    stackBuilder.addParentStack(LoginActivity.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) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    // mId allows you to update the notification later on.
                    mNotificationManager.notify(Common.COMMON_ID, mBuilder.build());
                }
            }

            @Override
            public void onError() {

            }
        });
    }
}

From source file:rikka.materialpreference.RingtonePreference.java

public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RingtonePreference, defStyleAttr,
            defStyleRes);/*from   w  w  w.j  a va 2s  . c o  m*/

    mRingtoneType = TypedArrayUtils.getInt(a, R.styleable.RingtonePreference_ringtoneType,
            R.styleable.RingtonePreference_android_ringtoneType, RingtoneManager.TYPE_RINGTONE);
    mShowDefault = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showDefault,
            R.styleable.RingtonePreference_android_showDefault, true);
    mShowSilent = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showSilent,
            R.styleable.RingtonePreference_android_showSilent, true);
    mSummaryNone = a.getString(R.styleable.RingtonePreference_summaryNone);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr, defStyleRes);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    a.recycle();
}

From source file:de.lespace.apprtc.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w w w  .  j  a  v  a  2 s. c om
*/
private void sendNotification(String message) {
    Intent intent = new Intent(this, ConnectActivity.class);
    // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

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

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 // ID of notification
            , notificationBuilder.build());

}

From source file:dk.kk.cykelsuperstier.reminders.AlarmReceiver.java

private void createNotification(Context context, int repetition) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(context, SplashActivity.class);
    intent.setData(Uri.fromParts("cykelsuperstier", "custom", "1"));
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    String description = CykelPlanenApplication.getString("reminder_alert_text");
    builder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_launcher)
            .setTicker(context.getResources().getString(R.string.app_name) + " " + description)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentText(description)
            .setContentTitle(context.getResources().getString(R.string.app_name));
    builder.setStyle(new NotificationCompat.InboxStyle());
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (alarmSound == null) {
        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    }/*  w w  w. j  ava  2s .  com*/
    builder.setSound(alarmSound);
    Notification n = builder.build();
    notificationManager.notify(1, n);
}

From source file:com.spoiledmilk.cykelsuperstier.reminders.AlarmReceiver.java

private void createNotification(Context context, int repetition) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(context, SplashActivity.class);
    intent.setData(Uri.fromParts("cykelsuperstier", "custom", "1"));
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    String description = CykelsuperstierApplication.getString("reminder_alert_text");
    builder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_launcher)
            .setTicker(context.getResources().getString(R.string.app_name) + " " + description)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentText(description)
            .setContentTitle(context.getResources().getString(R.string.app_name));
    builder.setStyle(new NotificationCompat.InboxStyle());
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (alarmSound == null) {
        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    }//from  www.j a va 2s  .  c  o m
    builder.setSound(alarmSound);
    Notification n = builder.build();
    notificationManager.notify(1, n);
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity.java

public void playRingtone() {
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (mAudioManager != null) {
        userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }//  w  w  w  .j a v a 2  s .co  m
    mp = new MediaPlayer();

    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    try {
        mp.setDataSource(this, ringtoneUri);
        mp.setAudioStreamType(AudioManager.STREAM_ALARM);
        mp.setLooping(true);
        mp.prepare();
        mp.start();
    } catch (IOException ignore) {
    }
    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
            mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND);

}

From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java

private Uri getAlarmUri() {
    String ringtone = settings.getRingtone();
    Uri alert = null;//from  w  w  w  . j  a v  a 2  s. com
    if (ringtone != null) {
        alert = Uri.parse(ringtone);
    } else {
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        if (alert == null) {
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            if (alert == null) {
                alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            }
        }
    }
    return alert;
}