Guest User

Untitled

a guest
Feb 15th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. private PickRingtone pickRingtone = new PickRingtone();
  2.  
  3.     public static class PickRingtone extends ActivityResultContract<Integer, Uri> {
  4.         @NonNull
  5.         @Override
  6.         public Intent createIntent(@NonNull Context context, @NonNull Integer ringtoneType) {
  7.             Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
  8.             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
  9.             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
  10.             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
  11.                     Settings.System.DEFAULT_RINGTONE_URI);
  12.             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
  13.             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
  14.                     RingtoneManager.getActualDefaultRingtoneUri(PanelApp.app(),
  15.                             RingtoneManager.TYPE_RINGTONE));
  16.             return intent;
  17.         }
  18.  
  19.         @Override
  20.         public Uri parseResult(int resultCode, @Nullable Intent result) {
  21.             if (resultCode != Activity.RESULT_OK || result == null) {
  22.                 return null;
  23.             }
  24.             return result.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
  25.         }
  26.     }
  27.  
  28.  ActivityResultLauncher<Integer> mStartForResult = registerForActivityResult(pickRingtone,
  29.             result -> {
  30.                 if (result != null) {
  31.                     viewModel.setCallRingtone(result.toString());
  32.                     Preference callRingtonePreference = findPreference(AppConstants.PROPERTY_CALL_RINGTONE);
  33.                     if (callRingtonePreference != null)
  34.                         callRingtonePreference.callChangeListener(null);
  35.                 }
  36.             });
  37.  
  38.   mStartForResult.launch(requestCode);
Advertisement
Add Comment
Please, Sign In to add comment