Class MediaLibrary
Saves images and videos to the device photo gallery: Photos on iOS and the shared media collection on Android.
Referencing this class makes the build declare what saving needs: the
NSPhotoLibraryAddUsageDescription Info.plist string on iOS, and on
Android WRITE_EXTERNAL_STORAGE for Android 9 and older only. Later
Android versions need no permission. The iOS prompt text can be replaced
with the ios.NSPhotoLibraryAddUsageDescription build hint.
The callback is called on the EDT with true when the system accepted the
file. In the simulator the file is copied into a gallery folder in the
app home directory.
String path = FileSystemStorage.getInstance().getAppHomePath() + "photo.jpg";
MediaLibrary.saveImage(path, "My App", new SuccessCallback<Boolean>() {
public void onSucess(Boolean saved) {
Log.p("Saved to the gallery: " + saved);
}
});
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanTrue when this platform can save to a gallery.static voidsaveImage(String path, String album, SuccessCallback<Boolean> callback) Saves an image file to the gallery.static voidsaveVideo(String path, String album, SuccessCallback<Boolean> callback) Saves a video file to the gallery.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: implementation instance
-
isSupported
public static boolean isSupported()True when this platform can save to a gallery.
Returns
true when saving is supported
-
saveImage
Saves an image file to the gallery.
Parameters
-
path: theFileSystemStoragepath of a JPEG or PNG file -
album: an album name, or null for the default location. Android uses it as a folder under Pictures; iOS ignores it. -
callback: receives true on success; may be null
-
-
saveVideo
Saves a video file to the gallery.
Parameters
-
path: theFileSystemStoragepath of an MP4 or MOV file -
album: an album name, or null for the default location. Android uses it as a folder under Movies; iOS ignores it. -
callback: receives true on success; may be null
-
-