-
public final class Utils
-
-
Method Summary
Modifier and Type Method Description static booleancontainsIgnoreCase(Collection<String> collection, String key)static HashMap<String, Object>convertBundleObjectToHashMap(@NonNull() Bundle b)static ArrayList<HashMap<String, Object>>convertJSONArrayOfJSONObjectsToArrayListOfHashMaps(JSONArray jsonArray)static ArrayList<String>convertJSONArrayToArrayList(JSONArray array)static HashMap<String, Object>convertJSONObjectToHashMap(JSONObject b)static StringconvertToTitleCase(String text)static BitmapgetBitmapFromURL(@NonNull() String srcUrl)static longgetNowInMillis()static StringgetCurrentNetworkType(Context context)static StringgetDeviceNetworkType(@NonNull() Context context)static longgetMemoryConsumption()static DownloadedBitmapgetDownloadedBitmapPostFallbackIconCheck(boolean fallbackToAppIcon, Context context, @NonNull() DownloadedBitmap ic)static DownloadedBitmapgetNotificationBitmapWithTimeoutAndSize(String icoPath, boolean fallbackToAppIcon, Context context, CleverTapInstanceConfig config, long timeoutMillis, int sizeBytes)get bitmap from url within defined timeoutMillis bound and sizeBytes bound or else returnnull or app icon based on fallbackToAppIcon param static DownloadedBitmapgetNotificationBitmapWithTimeout(String icoPath, boolean fallbackToAppIcon, Context context, CleverTapInstanceConfig config, long timeoutMillis)static UrigetNotificationGifURI(String url, Context context, CleverTapInstanceConfig config, Clock clock)Saves an animated image from URL to a file and returns a content URIThis is the main function that orchestrates the two operations static voidcleanupOldGIFs(Context context, CleverTapInstanceConfig config, Clock clock)Cleans up old GIF image files from the push notification cache directory.Only removes GIF files that are one day (24 hours) or older, based on the timestampembedded in their filename. static intgetThumbnailImage(Context context, String image)static booleanhasPermission(@NonNull() Context context, @NonNull() String permission)Checks whether a particular permission is available or not. static booleanisActivityDead(Activity activity)static booleanisServiceAvailable(@NonNull() Context context, Class clazz)static StringoptionalStringKey(JSONObject o, String k)static voidrunOnUiThread(Runnable runnable)Handy method to post any runnable to run on the main thread. static voidsetPackageNameFromResolveInfoList(Context context, Intent launchIntent)static BundlestringToBundle(String content)static booleanvalidateCTID(String cleverTapID)static StringgetSCDomain(String domain)static booleanisRenderFallback(RemoteMessage remoteMessage, Context context)static voidnavigateToAndroidSettingsForNotifications(Context context)static booleanisMainProcess(Context context, String mainProcessName)static List<JSONObject>toJSONObjectList(JSONArray jsonArray)static doublehaversineDistance(Location coordinateA, Location coordinateB)Calculates the haversine distance between two locations on Earth. static StringreadAssetFile(Context context, String fileName)Reads the content of a file from the "assets" folder. static StringgetNormalizedName(@Nullable() String name)Get the CT normalized version of an event or a property name. static booleanareNamesNormalizedEqual(@Nullable() String name, @Nullable() String other)Check if two event/property names are equal with applied CT normalization -
-
Method Detail
-
containsIgnoreCase
static boolean containsIgnoreCase(Collection<String> collection, String key)
-
convertBundleObjectToHashMap
static HashMap<String, Object> convertBundleObjectToHashMap(@NonNull() Bundle b)
-
convertJSONArrayOfJSONObjectsToArrayListOfHashMaps
static ArrayList<HashMap<String, Object>> convertJSONArrayOfJSONObjectsToArrayListOfHashMaps(JSONArray jsonArray)
-
convertJSONArrayToArrayList
static ArrayList<String> convertJSONArrayToArrayList(JSONArray array)
-
convertJSONObjectToHashMap
static HashMap<String, Object> convertJSONObjectToHashMap(JSONObject b)
-
convertToTitleCase
static String convertToTitleCase(String text)
-
getBitmapFromURL
static Bitmap getBitmapFromURL(@NonNull() String srcUrl)
-
getNowInMillis
static long getNowInMillis()
-
getCurrentNetworkType
static String getCurrentNetworkType(Context context)
-
getDeviceNetworkType
static String getDeviceNetworkType(@NonNull() Context context)
-
getMemoryConsumption
static long getMemoryConsumption()
-
getDownloadedBitmapPostFallbackIconCheck
@NonNull() static DownloadedBitmap getDownloadedBitmapPostFallbackIconCheck(boolean fallbackToAppIcon, Context context, @NonNull() DownloadedBitmap ic)
-
getNotificationBitmapWithTimeoutAndSize
@NonNull() static DownloadedBitmap getNotificationBitmapWithTimeoutAndSize(String icoPath, boolean fallbackToAppIcon, Context context, CleverTapInstanceConfig config, long timeoutMillis, int sizeBytes)
get bitmap from url within defined timeoutMillis bound and sizeBytes bound or else returnnull or app icon based on fallbackToAppIcon param
-
getNotificationBitmapWithTimeout
@NonNull() static DownloadedBitmap getNotificationBitmapWithTimeout(String icoPath, boolean fallbackToAppIcon, Context context, CleverTapInstanceConfig config, long timeoutMillis)
-
getNotificationGifURI
@Nullable()@RequiresApi(value = 26) static Uri getNotificationGifURI(String url, Context context, CleverTapInstanceConfig config, Clock clock)
Saves an animated image from URL to a file and returns a content URIThis is the main function that orchestrates the two operations
-
cleanupOldGIFs
static void cleanupOldGIFs(Context context, CleverTapInstanceConfig config, Clock clock)
Cleans up old GIF image files from the push notification cache directory.Only removes GIF files that are one day (24 hours) or older, based on the timestampembedded in their filename.
This method expects GIF files to be named in the format "timestamp.gif" wheretimestamp is the creation time in milliseconds (e.g., "1234567890123.gif").Files that don't match this naming convention will be skipped.
- Parameters:
context- The application context used to access the cache directoryconfig- The CleverTap instance configuration containing logger and account information
-
getThumbnailImage
static int getThumbnailImage(Context context, String image)
-
hasPermission
static boolean hasPermission(@NonNull() Context context, @NonNull() String permission)
Checks whether a particular permission is available or not.
- Parameters:
context- The Android Contextpermission- The fully qualified Android permission name
-
isActivityDead
static boolean isActivityDead(Activity activity)
-
isServiceAvailable
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) static boolean isServiceAvailable(@NonNull() Context context, Class clazz)
-
optionalStringKey
static String optionalStringKey(JSONObject o, String k)
-
runOnUiThread
static void runOnUiThread(Runnable runnable)
Handy method to post any runnable to run on the main thread.
- Parameters:
runnable- - task to be run
-
setPackageNameFromResolveInfoList
static void setPackageNameFromResolveInfoList(Context context, Intent launchIntent)
-
stringToBundle
static Bundle stringToBundle(String content)
- Parameters:
content- String which contains bundle information
-
validateCTID
static boolean validateCTID(String cleverTapID)
-
getSCDomain
static String getSCDomain(String domain)
-
isRenderFallback
static boolean isRenderFallback(RemoteMessage remoteMessage, Context context)
-
navigateToAndroidSettingsForNotifications
static void navigateToAndroidSettingsForNotifications(Context context)
-
isMainProcess
@WorkerThread() static boolean isMainProcess(Context context, String mainProcessName)
-
toJSONObjectList
static List<JSONObject> toJSONObjectList(JSONArray jsonArray)
-
haversineDistance
static double haversineDistance(Location coordinateA, Location coordinateB)
Calculates the haversine distance between two locations on Earth.
- Parameters:
coordinateA- The first location.coordinateB- The second location.
-
readAssetFile
static String readAssetFile(Context context, String fileName)
Reads the content of a file from the "assets" folder.
- Parameters:
context- The application context.fileName- The name of the file to be read from the "assets" folder.
-
getNormalizedName
static String getNormalizedName(@Nullable() String name)
Get the CT normalized version of an event or a property name.
- Parameters:
name- The event/property name
-
areNamesNormalizedEqual
static boolean areNamesNormalizedEqual(@Nullable() String name, @Nullable() String other)
Check if two event/property names are equal with applied CT normalization
- Parameters:
name- Event or property nameother- Event or property name to compare to
-
-
-
-