Example usage for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_PICKED_URI

Introduction

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

Prototype

String EXTRA_RINGTONE_PICKED_URI

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

Click Source Link

Document

Returned from the ringtone picker as a Uri .

Usage

From source file:org.telegram.ui.ProfileNotificationsActivity.java

@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            return;
        }/*  w ww .  ja  v a  2s.c  om*/
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == 12) {
            if (name != null) {
                editor.putString("sound_" + dialog_id, name);
                editor.putString("sound_path_" + dialog_id, ringtone.toString());
            } else {
                editor.putString("sound_" + dialog_id, "NoSound");
                editor.putString("sound_path_" + dialog_id, "NoSound");
            }
        }
        editor.commit();
        listView.invalidateViews();
    }
}

From source file:saphion.fragments.alarm.AlarmFragment.java

private void saveRingtoneUri(Intent intent) {
    Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    if (uri == null) {
        uri = Alarm.NO_RINGTONE_URI;
    }//  ww w  .  j ava 2 s. c o  m
    mSelectedAlarm.alert = uri;

    // Save the last selected ringtone as the default for new alarms
    if (!Alarm.NO_RINGTONE_URI.equals(uri)) {
        RingtoneManager.setActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_ALARM, uri);
    }
    asyncUpdateAlarm(mSelectedAlarm, false);
}

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

public void onClick(View v) {
    Log.e("lys", "onClick called");
    if (toneType == -1) {
        finish();/* www. j  a v  a 2  s. com*/
    }
    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:it.feio.android.omninotes.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case SPRINGPAD_IMPORT:
            Uri filesUri = intent.getData();
            String path = FileHelper.getPath(getActivity(), filesUri);
            // An IntentService will be launched to accomplish the import task
            Intent service = new Intent(getActivity(), DataBackupIntentService.class);
            service.setAction(DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD);
            service.putExtra(DataBackupIntentService.EXTRA_SPRINGPAD_BACKUP, path);
            getActivity().startService(service);
            break;

        case RINGTONE_REQUEST_CODE:
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String notificationSound = uri == null ? null : uri.toString();
            prefs.edit().putString("settings_notification_ringtone", notificationSound).apply();
            break;
        }/*www.ja va2  s .c  o m*/
    }
}

From source file:com.dycody.android.idealnote.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case SPRINGPAD_IMPORT:
            Uri filesUri = intent.getData();
            String path = FileHelper.getPath(getActivity(), filesUri);
            // An IntentService will be launched to accomplish the import task
            Intent service = new Intent(getActivity(), DataBackupIntentService.class);
            service.setAction(DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD);
            service.putExtra(DataBackupIntentService.EXTRA_SPRINGPAD_BACKUP, path);
            getActivity().startService(service);
            break;

        case RINGTONE_REQUEST_CODE:
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            String notificationSound = uri == null ? null : uri.toString();
            prefs.edit().putString("settings_notification_ringtone", notificationSound).apply();
            break;

        default://from  ww w .  j  a  v  a 2 s  . c  o m
            Log.e(Constants.TAG, "Wrong element choosen: " + requestCode);
        }
    }
}

From source file:org.telegram.ui.NotificationsSettingsActivity.java

@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        String name = null;/*from ww  w  .j  a v  a 2 s  .c o  m*/
        if (ringtone != null) {
            Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
            if (rng != null) {
                if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
                    name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
                } else {
                    name = rng.getTitle(getParentActivity());
                }
                rng.stop();
            }
        }

        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        if (requestCode == messageSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GlobalSound", name);
                editor.putString("GlobalSoundPath", ringtone.toString());
            } else {
                editor.putString("GlobalSound", "NoSound");
                editor.putString("GlobalSoundPath", "NoSound");
            }
        } else if (requestCode == groupSoundRow) {
            if (name != null && ringtone != null) {
                editor.putString("GroupSound", name);
                editor.putString("GroupSoundPath", ringtone.toString());
            } else {
                editor.putString("GroupSound", "NoSound");
                editor.putString("GroupSoundPath", "NoSound");
            }
        }
        editor.commit();
        listView.invalidateViews();
    }
}

From source file:com.amaze.filemanager.fragments.Main.java

private void returnIntentResults(File file) {
    MAIN_ACTIVITY.mReturnIntent = false;

    Intent intent = new Intent();
    if (MAIN_ACTIVITY.mRingtonePickerIntent) {

        Uri mediaStoreUri = MediaStoreHack.getUriFromFile(file.getPath(), getActivity());
        System.out.println(mediaStoreUri.toString() + "\t" + MimeTypes.getMimeType(file));
        intent.setDataAndType(mediaStoreUri, MimeTypes.getMimeType(file));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri);
        getActivity().setResult(getActivity().RESULT_OK, intent);
        getActivity().finish();//from   w ww.j ava  2 s.c om
    } else {

        Log.d("pickup", "file");
        intent.setData(Uri.fromFile(file));
        getActivity().setResult(getActivity().RESULT_OK, intent);
        getActivity().finish();
    }
}

From source file:com.filemanager.free.fragments.Main.java

private void returnIntentResults(File file) {
    MAIN_ACTIVITY.mReturnIntent = false;

    Intent intent = new Intent();
    if (MAIN_ACTIVITY.mRingtonePickerIntent) {

        Uri mediaStoreUri = MediaStoreHack.getUriFromFile(file.getPath(), getActivity());
        System.out.println(mediaStoreUri.toString() + "\t" + MimeTypes.getMimeType(file));
        intent.setDataAndType(mediaStoreUri, MimeTypes.getMimeType(file));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri);
        getActivity().setResult(Activity.RESULT_OK, intent);
        getActivity().finish();/*from   w  w w.ja va2  s .  co m*/
    } else {

        Log.d("pickup", "file");
        intent.setData(Uri.fromFile(file));
        getActivity().setResult(getActivity().RESULT_OK, intent);
        getActivity().finish();
    }
}

From source file:com.amaze.filemanager.fragments.MainFragment.java

/**
 * Returns the intent with uri corresponding to specific {@link HybridFileParcelable} back to external app
 *///  w w w  . j  a  v a  2  s . co m
public void returnIntentResults(HybridFileParcelable baseFile) {

    getMainActivity().mReturnIntent = false;

    Intent intent = new Intent();
    if (getMainActivity().mRingtonePickerIntent) {

        Uri mediaStoreUri = MediaStoreHack.getUriFromFile(baseFile.getPath(), getActivity());
        Log.d(getClass().getSimpleName(), mediaStoreUri.toString() + "\t"
                + MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory()));
        intent.setDataAndType(mediaStoreUri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory()));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri);
        getActivity().setResult(FragmentActivity.RESULT_OK, intent);
        getActivity().finish();
    } else {

        Log.d("pickup", "file");

        Intent intentresult = new Intent();

        Uri resultUri = Utils.getUriForBaseFile(getActivity(), baseFile);
        intentresult.setAction(Intent.ACTION_SEND);
        intentresult.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        if (resultUri != null)
            intentresult.setDataAndType(resultUri, MimeTypes.getExtension(baseFile.getPath()));

        getActivity().setResult(FragmentActivity.RESULT_OK, intentresult);
        getActivity().finish();
        //mode.finish();
    }
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

private void returnIntentResults(File file) {
    MAIN_ACTIVITY.mReturnIntent = false;

    Intent intent = new Intent();
    if (MAIN_ACTIVITY.mRingtonePickerIntent) {

        Uri mediaStoreUri = MediaStoreHack.getUriFromFile(file.getPath(), getActivity());
        System.out.println(mediaStoreUri.toString() + "\t" + MimeTypes.getMimeType(file));
        intent.setDataAndType(mediaStoreUri, MimeTypes.getMimeType(file));
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri);
        getActivity().setResult(FragmentActivity.RESULT_OK, intent);
        getActivity().finish();/*from   w  w w . j  a v  a2  s  . co m*/
    } else {

        Log.d("pickup", "file");
        intent.setData(Uri.fromFile(file));
        getActivity().setResult(FragmentActivity.RESULT_OK, intent);
        getActivity().finish();
    }
}