You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Open Gallery or Specific Image externally (on Android) #103
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
@PluginMethodpublicvoidopenGallery(PluginCallcall) {
try {
StringimageUriString = call.getString("uri"); // Optional URIIntentintent;
if (imageUriString != null && !imageUriString.isEmpty()) {
// If URI provided, open the specific imageUriimageUri = Uri.parse(imageUriString);
intent = newIntent(Intent.ACTION_VIEW);
intent.setDataAndType(imageUri, "image/*");
} else {
// Otherwise, open the default gallery appintent = newIntent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Open externallygetActivity().startActivity(intent);
call.resolve();
} catch (Exceptione) {
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.
Activity