Class MediaManager

java.lang.Object
com.cloudinary.android.MediaManager

public class MediaManager
extends java.lang.Object
Main class used as entry point to any operation against Cloudinary. Use get() to get an instance. Must be initialized before use, see init(Context, SignatureProvider, Map).
  • Field Details

  • Method Details

    • init

      public static void init​(@NonNull android.content.Context context)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
    • init

      public static void init​(@NonNull android.content.Context context, @Nullable java.util.Map config)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
      config - Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
    • init

      public static void init​(@NonNull android.content.Context context, @Nullable com.cloudinary.Configuration config)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
      config - Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
    • init

      public static void init​(@NonNull android.content.Context context, @Nullable SignatureProvider signatureProvider)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
      signatureProvider - A signature provider. Needed if using signed uploads.
    • init

      public static void init​(@NonNull android.content.Context context, @Nullable SignatureProvider provider, @Nullable java.util.Map config)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
      provider - A signature provider. Needed if using signed uploads.
      config - Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
    • init

      public static void init​(@NonNull android.content.Context context, @Nullable SignatureProvider provider, @Nullable com.cloudinary.Configuration config)
      Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of Application.onCreate().
      Parameters:
      context - Android context for initializations. Does not get cached.
      provider - A signature provider. Needed if using signed uploads.
      config - Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
    • get

      public static MediaManager get()
      Entry point for any operation against Cloudinary
      Returns:
      An instance of the MediaManager class to run operations against cloudinary.
    • setLogLevel

      public static void setLogLevel​(LogLevel logLevel)
      Set the log level. In order to affect initialization logging this can be set before calling init(Context).
      Parameters:
      logLevel - The log level to set, see LogLevel.
    • getCloudinary

      public com.cloudinary.Cloudinary getCloudinary()
      Get an instance of the Cloudinary class for raw operations (not wrapped).
      Returns:
      A Pre-configured Cloudinary instance
    • url

      public com.cloudinary.Url url()
      Get a Cloudinary Url object used to construct urls to access and transform pre-uploaded resources.
    • cancelRequest

      public boolean cancelRequest​(java.lang.String requestId)
      Cancel an upload request.
      Parameters:
      requestId - Id of the request to cancel.
      Returns:
      True if the request was found and cancelled successfully.
    • cancelAllRequests

      public int cancelAllRequests()
      * Cancel all upload requests.
      Returns:
      The count of canceled requests and running jobs.
    • upload

      public UploadRequest upload​(int rawResourceId)
      Entry point to start an upload of a raw resource.
      Parameters:
      rawResourceId - Android R generated raw resource identifier
      Returns:
      UploadRequest instance. Setup the request and call UploadRequest.dispatch() to start uploading.
    • upload

      public UploadRequest upload​(android.net.Uri uri)
      Entry point to start an upload of a uri.
      Parameters:
      uri - Android R generated raw resource identifier
      Returns:
      UploadRequest instance. Setup the request and call UploadRequest.dispatch() to start uploading.
    • upload

      public UploadRequest upload​(byte[] bytes)
      Entry point to start an upload of a byte array.
      Parameters:
      bytes - A byte array containing image/video/raw data to upload.
      Returns:
      UploadRequest instance. Setup the request and call UploadRequest.dispatch() to start uploading.
    • upload

      public UploadRequest upload​(java.lang.String filePath)
      Entry point to start an upload of a file.
      Parameters:
      filePath - An absolute file path to upload.
      Returns:
      UploadRequest instance. Setup the request and call UploadRequest.dispatch() to start uploading.
    • upload

      public UploadRequest upload​(Payload payload)
      Entry point to start an upload of a generic payload. Only use this with custom payloads.
      Parameters:
      payload - The payload to upload
      Returns:
      UploadRequest instance. Setup the request and call UploadRequest.dispatch() to start uploading.
    • getGlobalUploadPolicy

      public GlobalUploadPolicy getGlobalUploadPolicy()
      Return the global upload policy.
    • setGlobalUploadPolicy

      public void setGlobalUploadPolicy​(GlobalUploadPolicy globalUploadPolicy)
      Setup the global upload policy for Cloudinary.
      Parameters:
      globalUploadPolicy - The policy to set. See UploadPolicy.Builder.
    • registerCallback

      public void registerCallback​(UploadCallback callback)
      Register a callback for state changes and results of requests.
      Parameters:
      callback - The callback to activate upon state changes and results.
    • unregisterCallback

      public void unregisterCallback​(UploadCallback callback)
      Unregister a callback
      Parameters:
      callback - The callback to unregister.
    • popPendingResult

      public UploadResult popPendingResult​(java.lang.String requestId)
      Fetch a pending result. In case the app wasn't awake when the upload stopped, successfully or not, the result can be fetched here. Assuming the app wakes up through a the callback service defined in the manifest, it should get the full results by calling this method. Note: the result is cleared once this method is called.
      Parameters:
      requestId - Id of the request to fetch results for.
      Returns:
      The upload result.
    • responsiveUrl

      public ResponsiveUrl responsiveUrl​(boolean autoWidth, boolean autoHeight, @NonNull java.lang.String cropMode, @NonNull java.lang.String gravity)
      Create a new responsive url generator instance.
      Parameters:
      autoWidth - Specifying true will adjust the image width to the view width
      autoHeight - Specifying true will adjust the image height to the view height
      cropMode - Crop mode to use in the transformation. See here).
      gravity - Gravity to use in the transformation. See here).
    • responsiveUrl

      public ResponsiveUrl responsiveUrl​(@NonNull ResponsiveUrl.Preset preset)
      Create a new responsive url generator instance.
      Parameters:
      preset - A predefined set of responsive parameters, see ResponsiveUrl.Preset.
      Returns:
      The responsive url generator. Use ResponsiveUrl.generate(java.lang.String, android.view.View, com.cloudinary.android.ResponsiveUrl.Callback) to build the final url.
    • responsiveUrl

      public void responsiveUrl​(android.view.View view, com.cloudinary.Url baseUrl, ResponsiveUrl.Preset preset, ResponsiveUrl.Callback callback)
      Create a new responsive url.
      Parameters:
      view - The view to adapt the resource dimensions to.
      baseUrl - A url to be used as a base to the responsive transformation. This url can contain any configurations and transformations. The generated responsive transformation will be chained as the last transformation in the url. Important: When generating using a base url, it's preferable to not include any cropping/scaling in the original transformations.
      preset - A predefined set of responsive parameters, see ResponsiveUrl.Preset.
      callback - Callback to called when the modified Url is ready.
    • responsiveUrl

      public void responsiveUrl​(android.view.View view, java.lang.String publicId, ResponsiveUrl.Preset preset, ResponsiveUrl.Callback callback)
      Create a new responsive url.
      Parameters:
      view - The view to adapt the resource dimensions to.
      publicId - The public id of the cloudinary resource
      preset - A predefined set of responsive parameters, see ResponsiveUrl.Preset.
      callback - Callback to called when the modified Url is ready.
    • setDownloadRequestBuilderFactory

      public void setDownloadRequestBuilderFactory​(DownloadRequestBuilderFactory factory)
      Set a DownloadRequestBuilderFactory factory that will construct the DownloadRequestBuilder instance, to be used when creating download requests using download(Context).
    • download

      public DownloadRequestBuilder download​(@NonNull android.content.Context context)
      Create a new DownloadRequestBuilder to be used to create a download request.
      Parameters:
      context - Android context
      Returns:
      The DownloadRequestBuilder that will create the download request.