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:my.location.GcmIntentService.java

private void sendNotification(String message) {
    LoginSqlite loginSqlite = new LoginSqlite(this.getApplicationContext());

    Intent it = null;//from ww w. ja v  a2  s  .  com

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    GcmMsgJsonClass gcmMsgJsonClass = new Gson().fromJson(message, GcmMsgJsonClass.class);

    if (gcmMsgJsonClass.getNotificationUserType() != null
            && (gcmMsgJsonClass.isBusiness() && gcmMsgJsonClass.getNotificationUserType().equals("motoboy"))
    // condition to evaluate user registered with both motoboy and business usertype registrations.
    // It prevents this user to create an intent-activity that the user is not currently logged on
    // It was created to let DEVELOPERS navigate from one usertype to another during testing.
    // Realistically, a user wouldn't post nor confirm a service to itself.
    //             || gcmMsgJsonClass.isMotoboy() && gcmMsgJsonClass.getNotificationUserType().equals("business")
    ) {
        it = new Intent(this, MainBusinActivity.class);
        Bundle params = new Bundle();
        params.putLong("businessId", gcmMsgJsonClass.getBusinId());
        params.putString("username", gcmMsgJsonClass.getBusinUsername());
        it.putExtras(params);
        it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    } else if (gcmMsgJsonClass.getNotificationUserType() != null
            && (gcmMsgJsonClass.isMotoboy() && gcmMsgJsonClass.getNotificationUserType().equals("business")) // condition to evaluate user registered with both motoboy and business usertype registrations.
    // It prevents this user to create an intent-activity that the user is not currently logged on
    // It was created to let DEVELOPERS navigate from one usertype to another during testing.
    // Realistically, a user wouldn't post nor confirm a service to itself.
    //             || gcmMsgJsonClass.isBusiness() && gcmMsgJsonClass.getNotificationUserType().equals("motoboy")
    ) {
        it = new Intent(this, MainMotoActivity.class);
        Bundle params = new Bundle();
        params.putLong("motoboyId", gcmMsgJsonClass.getMotoId());
        params.putString("username", gcmMsgJsonClass.getMotoUsername());
        it.putExtras(params);
        it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // when used by itself activity will not be reloaded
        //           it.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    } else if (gcmMsgJsonClass.isConInvitMoto()) {

        it = new Intent(this, TabsMotoboyActivity.class);
        Bundle params = new Bundle();
        params.putString("motoboyId", String.valueOf(gcmMsgJsonClass.getMotoId()));
        params.putString("username", gcmMsgJsonClass.getMotoUsername());
        params.putString("currentTab", gcmMsgJsonClass.getCurrentTab());
        it.putExtras(params);

    } else if (gcmMsgJsonClass.isConAcceptInvitMoto()) {

        it = new Intent(this, TabsMotoboyActivity.class);
        Bundle params = new Bundle();
        params.putString("motoboyId", String.valueOf(gcmMsgJsonClass.getMotoId()));
        params.putString("username", gcmMsgJsonClass.getMotoUsername());
        params.putString("currentTab", gcmMsgJsonClass.getCurrentTab());
        it.putExtras(params);

    } else if (gcmMsgJsonClass.isConInvitBusin()) {

        it = new Intent(this, TabsBusinessActivity.class);
        Bundle params = new Bundle();
        params.putString("businessId", String.valueOf(gcmMsgJsonClass.getBusinId()));
        params.putString("username", gcmMsgJsonClass.getBusinUsername());
        params.putString("currentTab", gcmMsgJsonClass.getCurrentTab());
        it.putExtras(params);

    } else if (gcmMsgJsonClass.isConAcceptInvitBusin()) {

        it = new Intent(this, TabsBusinessActivity.class);
        Bundle params = new Bundle();
        params.putString("businessId", String.valueOf(gcmMsgJsonClass.getBusinId()));
        params.putString("username", gcmMsgJsonClass.getBusinUsername());
        params.putString("currentTab", gcmMsgJsonClass.getCurrentTab());
        it.putExtras(params);

    } else if (gcmMsgJsonClass.isResetPassword()) {

        it = new Intent(this, ResetPasswordActivity.class);
        Bundle params = new Bundle();
        params.putLong("businessId", gcmMsgJsonClass.getBusinId());
        params.putString("username", gcmMsgJsonClass.getBusinUsername());
        params.putString("navigate", gcmMsgJsonClass.getNavigate());
        it.putExtras(params);

    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, it, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setAutoCancel(true)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))
            .setSmallIcon(R.drawable.motorcycle_notification);

    if (gcmMsgJsonClass.isMotoboy()) {

        mBuilder.setContentTitle(gcmMsgJsonClass.getBusinUsername())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(gcmMsgJsonClass.getToAddress()))
                //                  +
                //                  gcmMsgJsonClass.getServiceDescription()))  
                //            .setContentText(
                //                  getResources().getText(R.string.service_title_address)
                //                  + "\n" +
                //                  gcmMsgJsonClass.getToAddress()
                //                  + "\n" +
                //                  getResources().getText(R.string.service_request)
                //                  + "\n" +
                //                  gcmMsgJsonClass.getServiceDescription())
                .setTicker(gcmMsgJsonClass.getBusinUsername());
    } else if (gcmMsgJsonClass.isBusiness()) {
        mBuilder.setContentTitle(gcmMsgJsonClass.getMotoUsername())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(
                        getResources().getText(R.string.service_time_estimated_pickup).toString().concat(" ")
                                .concat(DateFormatService
                                        .time24hourFormatString(gcmMsgJsonClass.getEstimatedDeliveryTime()))
                                .concat(".")))
                .setContentText(
                        getResources().getText(R.string.service_time_estimated_pickup).toString().concat(" ")
                                .concat(DateFormatService
                                        .time24hourFormatString(gcmMsgJsonClass.getEstimatedDeliveryTime())
                                        .concat(".")))
                .setTicker(gcmMsgJsonClass.getMotoUsername());

    } else if (gcmMsgJsonClass.isConInvitMoto()) {
        mBuilder.setContentTitle(getResources().getText(R.string.invitation_title).toString())
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(getResources().getText(R.string.invitation).toString().concat(" ")
                                .concat(gcmMsgJsonClass.getBusinUsername()).concat(".")))
                .setTicker(gcmMsgJsonClass.getBusinUsername().concat(" ")
                        .concat(getResources().getText(R.string.invitation_ticker).toString()));

    } else if (gcmMsgJsonClass.isConAcceptInvitMoto()) {
        mBuilder.setContentTitle(getResources().getText(R.string.acceptInvitation_title).toString())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(gcmMsgJsonClass.getBusinUsername()
                        .concat(" ").concat(getResources().getText(R.string.acceptInvitation).toString())))
                .setTicker(gcmMsgJsonClass.getBusinUsername().concat(" ")
                        .concat(getResources().getText(R.string.acceptInvitation_ticker).toString()));

    } else if (gcmMsgJsonClass.isConInvitBusin()) {
        mBuilder.setContentTitle(getResources().getText(R.string.invitation_title).toString())
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(getResources().getText(R.string.invitation).toString().concat(" ")
                                .concat(gcmMsgJsonClass.getMotoUsername()).concat(".")))
                .setTicker(gcmMsgJsonClass.getMotoUsername().concat(" ")
                        .concat(getResources().getText(R.string.invitation_ticker).toString()));

    } else if (gcmMsgJsonClass.isConAcceptInvitBusin()) {
        mBuilder.setContentTitle(getResources().getText(R.string.acceptInvitation_title).toString())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(gcmMsgJsonClass.getMotoUsername()
                        .concat(" ").concat(getResources().getText(R.string.acceptInvitation).toString())))
                .setTicker(gcmMsgJsonClass.getMotoUsername().concat(" ")
                        .concat(getResources().getText(R.string.acceptInvitation_ticker).toString()));

    } else if (gcmMsgJsonClass.isResetPassword()) {
        mBuilder.setContentTitle(getResources().getText(R.string.password_create_title).toString())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(gcmMsgJsonClass.getBusinUsername()
                        .concat(" ").concat(getResources().getText(R.string.password_create).toString())))
                .setTicker(getResources().getText(R.string.password_create_ticker).toString());

    }

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

protected void initTone() {
    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (alert == null) {
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alert == null) {
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        }//from  ww w .  j  a  v a  2s .c om
    }
    uri = alert;
}

From source file:com.silentcircle.contacts.detail.ContactLoaderFragment.java

private void doPickRingtone() {

    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    // Allow user to pick 'Default'
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    // Show only ringtones
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
    // Don't show 'Silent'
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);

    Uri ringtoneUri;//from w w w . j  a v  a 2  s. c om
    if (mCustomRingtone != null) {
        ringtoneUri = Uri.parse(mCustomRingtone);
    } else {
        // Otherwise pick default ringtone Uri so that something is selected.
        ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    }

    // Put checkmark next to the current ringtone for this contact
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);

    // Launch!
    startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE);
}

From source file:org.linphone.LinphoneService.java

private synchronized void startRinging() {
    try {// ww w.jav a2  s .c  o m
        if (mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) && mVibrator != null) {
            long[] patern = { 0, 1000, 1000 };
            mVibrator.vibrate(patern, 1);
        }
        if (mRingerPlayer == null) {
            mRingerPlayer = new MediaPlayer();
            mRingerPlayer.setAudioStreamType(AudioManager.STREAM_RING);
            mRingerPlayer.setDataSource(getApplicationContext(),
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
            mRingerPlayer.prepare();
            mRingerPlayer.setLooping(true);
            mRingerPlayer.start();
        } else {
            Log.w(LinphoneService.TAG, "already ringing");
        }
    } catch (Exception e) {
        Log.e(LinphoneService.TAG, "cannot handle incoming call", e);
    }

}

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

@Override
public void onIncomingCall(final String from) {

    // Notify UI that registration has completed, so the progress indicator can be hidden.
    /*/*from  w w w .  jav  a2  s .c o m*/
            //Send Broadcast message to Service
            Intent registrationComplete = new Intent(QuickstartPreferences.INCOMING_CALL);
            LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
            
            startActivity(intent);*/

    /* Intent intent = new Intent(this, ConnectActivity.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
     Intent intent = new Intent(this,CallActivity.class);
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);*/
    // r.stop();
    //startActivity(intent);

    roomConnectionParameters.to = from;
    roomConnectionParameters.initiator = false;
    DialogFragment newFragment = new RTCConnection.CallDialogFragment();

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

    if (alert == null) {
        // alert is null, using backup
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        // I can't see this ever being null (as always have a default notification)
        // but just incase
        if (alert == null) {
            // alert backup is null, using 2nd backup
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALL);
        }
    }
    r = RingtoneManager.getRingtone(getApplicationContext(), alert);
    //  r.play();

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.add(newFragment, "loading");
    transaction.commitAllowingStateLoss();

}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

public void onClick(View v) {
    Log.e("lys", "onClick called");
    if (toneType == -1) {
        finish();/*from   w w  w. j a  va  2  s .c  o m*/
    }
    Intent resultIntent = new Intent();
    ContentResolver resolver = getContentResolver();
    switch (v.getId()) {
    case R.id.ok:
        //if(mSelectedId >= 0 && mSelectedId != SILENT_ID && mSelectedId != DEFAULT_ID) 
        //{
        //   Log.e("lys","onClick mSelectedId == "+mSelectedId);
        //   ContentValues values = new ContentValues(2);
        //   if(toneActivityType == ALARM_TYPE)
        //   { 
        //      values.put(MediaStore.Audio.Media.IS_ALARM, "1");
        //   }
        //   else if(toneActivityType==NOTIFICATION_TYPE)
        //   { 
        //      values.put(MediaStore.Audio.Media.IS_NOTIFICATION, "1");
        //   }   
        //   else//! if(toneType==RINGTONE_TYPE) by duwenhua
        //   { 
        //      values.put(MediaStore.Audio.Media.IS_RINGTONE, "1");
        //   }

        Log.e("lys", "onClick values == " + mSelectedUri);
        //    resolver.update(mSelectedUri, values, null, null);
        //   resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri);
        //   setResult(RESULT_OK, resultIntent);
        //Toast.makeText(this, "mSelectedUri==" + mSelectedUri,
        //      Toast.LENGTH_LONG).show();
        //   finish();
        //}
        //else if(mSelectedId == SILENT_ID) 
        //{
        //resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri);
        //setResult(RESULT_OK, resultIntent);
        //Toast.makeText(this, "mSelectedUri==" + mSelectedUri,
        //      Toast.LENGTH_LONG).show();
        //finish();
        //}
        if (mSelectedId == SILENT_ID) {
            mSelectedUri = null;
        } else if (mSelectedId == DEFAULT_ID) {
            mSelectedUri = mUriForDefaultItem;
        } else {
            Log.e("lys", "onClick values mSelectedId == " + mSelectedId);

            //wuqingliang modify begin20130307 for the first time entery the ringtonePickerActivity, and the ringtone is in EXTERNAL_CONTENT_URI
            //user click ok button in TAP ringtone.
            if (BaseUri != MediaStore.Audio.Media.INTERNAL_CONTENT_URI
                    && BaseUri != MediaStore.Audio.Media.EXTERNAL_CONTENT_URI) {
                mSelectedUri = mExistingUri;
            } else {
                mSelectedUri = ContentUris.withAppendedId(BaseUri, mSelectedId);
            }
            //wuqingliang modify end

        }
        resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri);

        RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, mSelectedUri);

        setResult(RESULT_OK, resultIntent);
        //Toast.makeText(this, "mSelectedUri==" + mSelectedUri,
        //      Toast.LENGTH_LONG).show();
        finish();
        break;

    case R.id.cancel:
        setResult(RESULT_CANCELED);
        stopMediaPlayer();
        finish();
        break;
    }
}

From source file:com.ferdi2005.secondgram.voip.VoIPService.java

private void startRinging() {
    FileLog.d("starting ringing for call " + call.id);
    dispatchStateChanged(STATE_WAITING_INCOMING);
    //ringtone=RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
    //ringtone.play();
    SharedPreferences prefs = getSharedPreferences("Notifications", MODE_PRIVATE);
    ringtonePlayer = new MediaPlayer();
    ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override/*from w  w  w.j av  a 2 s. c o m*/
        public void onPrepared(MediaPlayer mediaPlayer) {
            ringtonePlayer.start();
        }
    });
    ringtonePlayer.setLooping(true);
    ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING);
    try {
        String notificationUri;
        if (prefs.getBoolean("custom_" + user.id, false))
            notificationUri = prefs.getString("ringtone_path_" + user.id,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
        else
            notificationUri = prefs.getString("CallsRingtonePath",
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString());
        ringtonePlayer.setDataSource(this, Uri.parse(notificationUri));
        ringtonePlayer.prepareAsync();
    } catch (Exception e) {
        FileLog.e(e);
        if (ringtonePlayer != null) {
            ringtonePlayer.release();
            ringtonePlayer = null;
        }
    }
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    int vibrate;
    if (prefs.getBoolean("custom_" + user.id, false))
        vibrate = prefs.getInt("calls_vibrate_" + user.id, 0);
    else
        vibrate = prefs.getInt("vibrate_calls", 0);
    if ((vibrate != 2 && vibrate != 4
            && (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE
                    || am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL))
            || (vibrate == 4 && am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)) {
        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        long duration = 700;
        if (vibrate == 1)
            duration /= 2;
        else if (vibrate == 3)
            duration *= 2;
        vibrator.vibrate(new long[] { 0, duration, 500 }, 0);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && !((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode()
            && NotificationManagerCompat.from(this).areNotificationsEnabled()) {
        showIncomingNotification();
        FileLog.d("Showing incoming call notification");
    } else {
        FileLog.d("Starting incall activity for incoming call");
        try {
            PendingIntent.getActivity(VoIPService.this, 12345,
                    new Intent(VoIPService.this, VoIPActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0)
                    .send();
        } catch (Exception x) {
            FileLog.e("Error starting incall activity", x);
        }
    }

}

From source file:dk.dr.radio.afspilning.Afspiller.java

void ringDenAlarm() {
      Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
      if (alert == null) {
          // alert is null, using backup
          alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase
              // alert backup is null, using 2nd backup
              alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
          }/*from w ww.  j  a va  2 s .  c  o  m*/
      }
      lydkilde = new AlarmLydkilde(alert.toString(), lydkilde);
      handler.postDelayed(startAfspilningIntern, 100);
      vibru(4000);
  }

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use
 * @param id The song ID./*  w w w .  ja v  a  2s.c  o m*/
 */
public static void setRingtone(final Context context, final long id) {
    final ContentResolver resolver = context.getContentResolver();
    final Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);
    try {
        final ContentValues values = new ContentValues(2);
        values.put(AudioColumns.IS_RINGTONE, "1");
        values.put(AudioColumns.IS_ALARM, "1");
        resolver.update(uri, values, null, null);
    } catch (final UnsupportedOperationException ignored) {
        return;
    }

    final String[] projection = new String[] { BaseColumns._ID, MediaColumns.DATA, MediaColumns.TITLE };

    final String selection = BaseColumns._ID + "=" + id;
    Cursor cursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null,
            null);
    try {
        if (cursor != null && cursor.getCount() == 1) {
            cursor.moveToFirst();
            RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, uri);
            final String message = context.getString(R.string.set_as_ringtone, cursor.getString(2));
            AppMsg.makeText(context, message, AppMsg.STYLE_CONFIRM).show();
        }
    } catch (Throwable ignored) {
        UIUtils.showLongMessage(context, R.string.ringtone_not_set);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}