Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class MediaLibrary
- Object
- 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);
}
});Methods
public static void setImplementation(CodenameOneImplementation impl) | Invoked internally from Display, this method is for internal use only |
public static boolean isSupported() | True when this platform can save to a gallery. |
public static void saveImage(String path, String album, SuccessCallback<Boolean> callback) | Saves an image file to the gallery. |
public static void saveVideo(String path, String album, SuccessCallback<Boolean> callback) | Saves a video file to the gallery. |
Inherited methods
Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Invoked internally from Display, this method is for internal use only
Parameters
implCodenameOneImplementation- implementation instance
isSupported
public static boolean isSupported()True when this platform can save to a gallery.
Returns
true when saving is supported
saveImage
public static void saveImage(String path, String album, SuccessCallback<Boolean> callback)Saves an image file to the gallery.
Parameters
pathString- the
FileSystemStoragepath of a JPEG or PNG file albumString- an album name, or null for the default location. Android uses it as a folder under Pictures; iOS ignores it.
callbackSuccessCallback<Boolean>- receives true on success; may be null
saveVideo
public static void saveVideo(String path, String album, SuccessCallback<Boolean> callback)Saves a video file to the gallery.
Parameters
pathString- the
FileSystemStoragepath of an MP4 or MOV file albumString- an album name, or null for the default location. Android uses it as a folder under Movies; iOS ignores it.
callbackSuccessCallback<Boolean>- receives true on success; may be null