Package com.cloudinary.android
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 Summary
Fields Modifier and Type Field Description static java.lang.StringACTION_REQUEST_FINISHEDstatic java.lang.StringACTION_REQUEST_STARTEDstatic java.lang.StringINTENT_EXTRA_REQUEST_IDstatic java.lang.StringINTENT_EXTRA_REQUEST_RESULT_STATUSstatic java.lang.StringVERSION -
Method Summary
Modifier and Type Method Description intcancelAllRequests()* Cancel all upload requests.booleancancelRequest(java.lang.String requestId)Cancel an upload request.DownloadRequestBuilderdownload(android.content.Context context)Create a newDownloadRequestBuilderto be used to create a download request.static MediaManagerget()Entry point for any operation against Cloudinarycom.cloudinary.CloudinarygetCloudinary()Get an instance of the Cloudinary class for raw operations (not wrapped).GlobalUploadPolicygetGlobalUploadPolicy()Return the global upload policy.static voidinit(android.content.Context context)Setup the library with the required parameters.static voidinit(android.content.Context context, SignatureProvider signatureProvider)Setup the library with the required parameters.static voidinit(android.content.Context context, SignatureProvider provider, com.cloudinary.Configuration config)Setup the library with the required parameters.static voidinit(android.content.Context context, SignatureProvider provider, java.util.Map config)Setup the library with the required parameters.static voidinit(android.content.Context context, com.cloudinary.Configuration config)Setup the library with the required parameters.static voidinit(android.content.Context context, java.util.Map config)Setup the library with the required parameters.UploadResultpopPendingResult(java.lang.String requestId)Fetch a pending result.voidregisterCallback(UploadCallback callback)Register a callback for state changes and results of requests.ResponsiveUrlresponsiveUrl(boolean autoWidth, boolean autoHeight, java.lang.String cropMode, java.lang.String gravity)Create a new responsive url generator instance.voidresponsiveUrl(android.view.View view, com.cloudinary.Url baseUrl, ResponsiveUrl.Preset preset, ResponsiveUrl.Callback callback)Create a new responsive url.voidresponsiveUrl(android.view.View view, java.lang.String publicId, ResponsiveUrl.Preset preset, ResponsiveUrl.Callback callback)Create a new responsive url.ResponsiveUrlresponsiveUrl(ResponsiveUrl.Preset preset)Create a new responsive url generator instance.voidsetDownloadRequestBuilderFactory(DownloadRequestBuilderFactory factory)Set aDownloadRequestBuilderFactoryfactory that will construct theDownloadRequestBuilderinstance, to be used when creating download requests usingdownload(Context).voidsetGlobalUploadPolicy(GlobalUploadPolicy globalUploadPolicy)Setup the global upload policy for Cloudinary.static voidsetLogLevel(LogLevel logLevel)Set the log level.voidunregisterCallback(UploadCallback callback)Unregister a callbackUploadRequestupload(byte[] bytes)Entry point to start an upload of a byte array.UploadRequestupload(int rawResourceId)Entry point to start an upload of a raw resource.UploadRequestupload(android.net.Uri uri)Entry point to start an upload of a uri.UploadRequestupload(Payload payload)Entry point to start an upload of a generic payload.UploadRequestupload(java.lang.String filePath)Entry point to start an upload of a file.com.cloudinary.Urlurl()Get a Cloudinary Url object used to construct urls to access and transform pre-uploaded resources.
-
Field Details
-
VERSION
public static final java.lang.String VERSION- See Also:
- Constant Field Values
-
INTENT_EXTRA_REQUEST_ID
public static final java.lang.String INTENT_EXTRA_REQUEST_ID- See Also:
- Constant Field Values
-
INTENT_EXTRA_REQUEST_RESULT_STATUS
public static final java.lang.String INTENT_EXTRA_REQUEST_RESULT_STATUS- See Also:
- Constant Field Values
-
ACTION_REQUEST_STARTED
public static final java.lang.String ACTION_REQUEST_STARTED- See Also:
- Constant Field Values
-
ACTION_REQUEST_FINISHED
public static final java.lang.String ACTION_REQUEST_FINISHED- See Also:
- Constant Field Values
-
-
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 ofApplication.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 ofApplication.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 ofApplication.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 ofApplication.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 ofApplication.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 ofApplication.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
Entry point for any operation against Cloudinary- Returns:
- An instance of the MediaManager class to run operations against cloudinary.
-
setLogLevel
Set the log level. In order to affect initialization logging this can be set before callinginit(Context).- Parameters:
logLevel- The log level to set, seeLogLevel.
-
getCloudinary
public com.cloudinary.Cloudinary getCloudinary()Get an instance of the Cloudinary class for raw operations (not wrapped).- Returns:
- A Pre-configured
Cloudinaryinstance
-
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
Entry point to start an upload of a raw resource.- Parameters:
rawResourceId- Android R generated raw resource identifier- Returns:
UploadRequestinstance. Setup the request and callUploadRequest.dispatch()to start uploading.
-
upload
Entry point to start an upload of a uri.- Parameters:
uri- Android R generated raw resource identifier- Returns:
UploadRequestinstance. Setup the request and callUploadRequest.dispatch()to start uploading.
-
upload
Entry point to start an upload of a byte array.- Parameters:
bytes- A byte array containing image/video/raw data to upload.- Returns:
UploadRequestinstance. Setup the request and callUploadRequest.dispatch()to start uploading.
-
upload
Entry point to start an upload of a file.- Parameters:
filePath- An absolute file path to upload.- Returns:
UploadRequestinstance. Setup the request and callUploadRequest.dispatch()to start uploading.
-
upload
Entry point to start an upload of a generic payload. Only use this with custom payloads.- Parameters:
payload- The payload to upload- Returns:
UploadRequestinstance. Setup the request and callUploadRequest.dispatch()to start uploading.
-
getGlobalUploadPolicy
Return the global upload policy. -
setGlobalUploadPolicy
Setup the global upload policy for Cloudinary.- Parameters:
globalUploadPolicy- The policy to set. SeeUploadPolicy.Builder.
-
registerCallback
Register a callback for state changes and results of requests.- Parameters:
callback- The callback to activate upon state changes and results.
-
unregisterCallback
Unregister a callback- Parameters:
callback- The callback to unregister.
-
popPendingResult
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. -
responsiveUrl
Create a new responsive url generator instance.- Parameters:
preset- A predefined set of responsive parameters, seeResponsiveUrl.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, seeResponsiveUrl.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 resourcepreset- A predefined set of responsive parameters, seeResponsiveUrl.Preset.callback- Callback to called when the modified Url is ready.
-
setDownloadRequestBuilderFactory
Set aDownloadRequestBuilderFactoryfactory that will construct theDownloadRequestBuilderinstance, to be used when creating download requests usingdownload(Context). -
download
Create a newDownloadRequestBuilderto be used to create a download request.- Parameters:
context- Android context- Returns:
- The
DownloadRequestBuilderthat will create the download request.
-