-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
Description
Combine the functionality to:
- Open the default gallery app (if no specific image is provided).
- Open a specific image (if a valid URI is provided).
This feature would simplify the API by providing a single method to handle both use cases, making it more intuitive and efficient for developers.
Use Case
- Open the gallery for general navigation.
- Open a specific image for viewing or editing, depending on the URI provided.
- Especially if you display a message - photos saved - with a button "Open Gallery"
Suggested Implementation
Add a method openGallery that accepts an optional URI. If the URI is provided, the function opens the specified image. If no URI is provided, it opens the default gallery app.
Code Example
@PluginMethod
public void openGallery(PluginCall call) {
try {
String imageUriString = call.getString("uri"); // Optional URI
Intent intent;
if (imageUriString != null && !imageUriString.isEmpty()) {
// If URI provided, open the specific image
Uri imageUri = Uri.parse(imageUriString);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(imageUri, "image/*");
} else {
// Otherwise, open the default gallery app
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open externally
getActivity().startActivity(intent);
call.resolve();
} catch (Exception e) {
call.reject("Failed to open gallery or image", e);
}
}Expected Behavior
- With URI: Opens the specified image in the system's gallery or media viewer.
- Without URI: Opens the default gallery app for general navigation.
Platform Support
- Android: Fully supported with both use cases.
- iOS: probably not possible
Notes
- The method should handle errors gracefully when the URI is invalid or no gallery app is available.
- For Android 7.0+ (API level 24), ensure URI handling is compatible with FileProvider to avoid FileUriExposedException.
Metadata
Metadata
Assignees
Labels
No labels