Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class MediaLibrary

  1. Object
  2. 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

impl CodenameOneImplementation
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

path String
the FileSystemStorage path of a JPEG or PNG file
album String
an album name, or null for the default location. Android uses it as a folder under Pictures; iOS ignores it.
callback SuccessCallback<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

path String
the FileSystemStorage path of an MP4 or MOV file
album String
an album name, or null for the default location. Android uses it as a folder under Movies; iOS ignores it.
callback SuccessCallback<Boolean>
receives true on success; may be null