-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Query MediaStore for media file URI for setting ringtone #4389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/4.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,7 @@ | |||||||
| import com.amaze.filemanager.filesystem.FileProperties; | ||||||||
| import com.amaze.filemanager.filesystem.HybridFile; | ||||||||
| import com.amaze.filemanager.filesystem.HybridFileParcelable; | ||||||||
| import com.amaze.filemanager.filesystem.MediaStoreHack; | ||||||||
| import com.amaze.filemanager.filesystem.SafRootHolder; | ||||||||
| import com.amaze.filemanager.filesystem.files.CryptUtil; | ||||||||
| import com.amaze.filemanager.filesystem.files.EncryptDecryptUtils; | ||||||||
|
|
@@ -136,6 +137,7 @@ | |||||||
| import jcifs.smb.SmbFile; | ||||||||
| import kotlin.collections.ArraysKt; | ||||||||
| import kotlin.collections.CollectionsKt; | ||||||||
| import kotlin.text.StringsKt; | ||||||||
|
|
||||||||
| public class MainFragment extends Fragment | ||||||||
| implements BottomBarButtonPath, | ||||||||
|
|
@@ -574,10 +576,26 @@ public void returnIntentResults(HybridFileParcelable[] baseFiles) { | |||||||
| HybridFileParcelable resultBaseFile = result.getKey(); | ||||||||
|
|
||||||||
| if (requireMainActivity().mRingtonePickerIntent) { | ||||||||
| intent.setDataAndType( | ||||||||
| resultUri, | ||||||||
| MimeTypes.getMimeType(resultBaseFile.getPath(), resultBaseFile.isDirectory())); | ||||||||
| intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, resultUri); | ||||||||
| // Query MediaStore to get the proper content URI for the selected audio file | ||||||||
| Uri mediaFileUri = | ||||||||
| MediaStoreHack.getUriForMusicMediaFrom(resultBaseFile.getPath(), requireContext()); | ||||||||
| if (mediaFileUri != null) { | ||||||||
| String filename = resultBaseFile.getName(); | ||||||||
| Uri properUri = | ||||||||
| mediaFileUri | ||||||||
| .buildUpon() | ||||||||
| .appendQueryParameter("canonical", "1") | ||||||||
| .appendQueryParameter("title", StringsKt.substringBeforeLast(filename, ".", "")) | ||||||||
| .build(); | ||||||||
| // Set the proper content URI as result | ||||||||
| intent.setDataAndType(properUri, "audio/*"); | ||||||||
|
||||||||
| intent.setDataAndType(properUri, "audio/*"); | |
| String mimeType = MimeTypes.getMimeType(resultBaseFile.getPath()); | |
| intent.setDataAndType(properUri, mimeType != null ? mimeType : "audio/*"); |
Copilot
AI
May 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Calling finish() here abruptly ends the host activity. Consider setting a canceled result (e.g., setResult(RESULT_CANCELED)) so the ringtone picker can handle the fallback gracefully instead of closing the entire app.
| .show(); | |
| .show(); | |
| requireActivity().setResult(FragmentActivity.RESULT_CANCELED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The KDoc comment above still refers to
scanFile(...). Update it to reflect the newscanFiles(...)method name and its parameters for clarity.