Class Batch
- java.lang.Object
-
- com.batch.android.Batch
-
public final class Batch extends java.lang.ObjectEntry point of the Batch library
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBatch.ActionsBatch Action managerstatic classBatch.DebugBatch Debug modulestatic classBatch.EventDispatcherBatch EventDispatcher modulestatic classBatch.InboxBatch Inbox modulestatic classBatch.MessagingBatch Messaging modulestatic classBatch.PushBatch Push modulestatic classBatch.UserBatch User module
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringACTION_REGISTRATION_IDENTIFIER_OBTAINEDIntent broadcasted locally by the SDK when a push registration identifier has been retrieved (also called "Push Token").static java.lang.StringBROADCAST_PERMISSION_SUFFIXPermission suffix for broadcasts triggered by Batch.static java.lang.StringDEFAULT_PLACEMENTDefault placementstatic java.lang.StringEXTRA_REGISTRATION_IDENTIFIERExtra containing the Registration Identifier for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcaststatic java.lang.StringEXTRA_REGISTRATION_PROVIDER_NAMEExtra containing the Registration Provider name for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcaststatic java.lang.StringEXTRA_REGISTRATION_SENDER_IDExtra containing the Sender ID (if any) for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcaststatic java.lang.StringNOTIFICATION_TAGNotification tag.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcopyBatchExtras(android.content.Intent from, android.content.Intent to)Copy Batch's internal data from an intent to another.static voidcopyBatchExtras(android.os.Bundle from, android.os.Bundle to)Copy Batch's internal data from intent extras to another bundle.static java.lang.StringgetAPIKey()Return the api key
If you call this method before calling setConfig, it will return nullstatic java.lang.StringgetBroadcastPermissionName(android.content.Context context)Get the broadcast permission name.static LoggerLevelgetLoggerLevel()Get the current logger levelstatic java.lang.StringgetSessionID()Get the id of the current session, random uuid used internaly by Batch to identify the app session.static BatchUserProfilegetUserProfile()Deprecated.Please use Batch.User methods insteadstatic booleanisOptedOut(android.content.Context context)Returns whether Batch has been opted out from or notstatic booleanisRunningInDevMode()Deprecated.This method is not needed, since all DEV API Keys start with "DEV".static voidonCreate(android.app.Activity activity)Method to call on your main activityActivity.onCreate(Bundle).static voidonDestroy(android.app.Activity activity)Method to call on your main activityActivity.onDestroy()
Calling this method if Batch is already stopped or not started will do nothingstatic voidonNewIntent(android.app.Activity activity, android.content.Intent intent)Method to call on your main activityActivity.onNewIntent(Intent)
Calling this method if Batch is already stopped or not started will do nothingstatic voidonServiceCreate(android.content.Context context, boolean userActivity)Method to call on your serviceService.onCreate()to start Batch.
You must call this method before any other on Batch.
Note that all Batch functionality is not available in this mode.static voidonServiceDestroy(android.content.Context context)Method to call on your serviceService.onDestroy()to stop Batch.
Calling this method if Batch is already stopped or not started will do nothing
static voidonStart(android.app.Activity activity)Method to call on your main activityActivity.onStart()to start Batch and support URL scheme events.
You must call this method before any other on Batch.
Will fail and log an Error if Givenactivityis null You call it before callingsetConfig(Config)Your app doesn't haveandroid.permission.INTERNETpermissionstatic voidonStop(android.app.Activity activity)Method to call on your main activityActivity.onStop()
Calling this method if Batch is already stopped or not started will do nothingstatic voidoptIn(android.content.Context context)Opt In to Batch SDK Usage.static voidoptOut(android.content.Context context)Opt Out from Batch SDK Usage.static voidoptOut(android.content.Context context, BatchOptOutResultListener listener)Opt Out from Batch SDK Usage.static voidoptOutAndWipeData(android.content.Context context)Opt Out from Batch SDK Usage.static voidoptOutAndWipeData(android.content.Context context, BatchOptOutResultListener listener)Opt Out from Batch SDK Usage.static voidsetConfig(Config config)Set the configuration of Batch.
You should call this method before any other, only one time.
Typically on the onCreate of your MainActivity.static voidsetFindMyInstallationEnabled(boolean enabled)Control whether Batch should enables the Find My Installation feature (default = true)static booleanshouldAutoRegisterForPush()Deprecated.Please remove this call, as it doesn't do anything anymorestatic booleanshouldUseAdvancedDeviceInformation()Can Batch use advanced device informationstatic booleanshouldUseAdvertisingID()Can Batch use Advertising IDstatic booleanshouldUseGoogleInstanceID()Deprecated.Please migrate to FCM
-
-
-
Field Detail
-
DEFAULT_PLACEMENT
public static final java.lang.String DEFAULT_PLACEMENT
Default placement- See Also:
- Constant Field Values
-
NOTIFICATION_TAG
public static final java.lang.String NOTIFICATION_TAG
Notification tag.Notifications displayed by Batch all have this tag. Useful if you need to cancel them, for example.
- See Also:
- Constant Field Values
-
BROADCAST_PERMISSION_SUFFIX
public static final java.lang.String BROADCAST_PERMISSION_SUFFIX
Permission suffix for broadcasts triggered by Batch. The actual permission is your package name + BROADCAST_PERMISSION_SUFFIXYou can call
getBroadcastPermissionName(Context)to get the full permission name.- See Also:
- Constant Field Values
-
ACTION_REGISTRATION_IDENTIFIER_OBTAINED
public static final java.lang.String ACTION_REGISTRATION_IDENTIFIER_OBTAINED
Intent broadcasted locally by the SDK when a push registration identifier has been retrieved (also called "Push Token").Registration information is defined by the
EXTRA_REGISTRATION_PROVIDER_NAMEandEXTRA_REGISTRATION_IDENTIFIERstring extras.- See Also:
- Constant Field Values
-
EXTRA_REGISTRATION_IDENTIFIER
public static final java.lang.String EXTRA_REGISTRATION_IDENTIFIER
Extra containing the Registration Identifier for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcast- See Also:
- Constant Field Values
-
EXTRA_REGISTRATION_PROVIDER_NAME
public static final java.lang.String EXTRA_REGISTRATION_PROVIDER_NAME
Extra containing the Registration Provider name for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcast- See Also:
- Constant Field Values
-
EXTRA_REGISTRATION_SENDER_ID
public static final java.lang.String EXTRA_REGISTRATION_SENDER_ID
Extra containing the Sender ID (if any) for aACTION_REGISTRATION_IDENTIFIER_OBTAINEDbroadcast- See Also:
- Constant Field Values
-
-
Method Detail
-
getAPIKey
public static java.lang.String getAPIKey()
Return the api key
If you call this method before calling setConfig, it will return null- Returns:
- API key if available, null otherwise
-
getUserProfile
@Deprecated public static BatchUserProfile getUserProfile()
Deprecated.Please use Batch.User methods insteadGet the current user profile.
You should use this method if you want to modify user language/region or provide a custom ID to identify this user (like an account).
Be carefull : Do not use it if you don't know what you are doing, giving a bad custom user ID can result in failure into offer delivery and restore
You must call this method afteronStart(Activity)otherwise it will return null- Returns:
- instance of BatchUser to set properties, null if you call it before onStart.
-
setConfig
public static void setConfig(Config config)
Set the configuration of Batch.
You should call this method before any other, only one time.
Typically on the onCreate of your MainActivity.- Parameters:
config-
-
shouldUseAdvertisingID
public static boolean shouldUseAdvertisingID()
Can Batch use Advertising ID- Returns:
-
shouldUseAdvancedDeviceInformation
public static boolean shouldUseAdvancedDeviceInformation()
Can Batch use advanced device information- Returns:
-
shouldUseGoogleInstanceID
@Deprecated public static boolean shouldUseGoogleInstanceID()
Deprecated.Please migrate to FCMCan Batch use the PlayServices Instance ID API (if available), or fallback to classic GCM.- Returns:
-
shouldAutoRegisterForPush
@Deprecated public static boolean shouldAutoRegisterForPush()
Deprecated.Please remove this call, as it doesn't do anything anymoreShould Batch automatically register to push notificaitons This method is not supported anymore: Batch will always register for push.- Returns:
- Always true
-
getLoggerLevel
public static LoggerLevel getLoggerLevel()
Get the current logger level- Returns:
-
getSessionID
public static java.lang.String getSessionID()
Get the id of the current session, random uuid used internaly by Batch to identify the app session.- Returns:
- session id if any, null otherwise
-
isRunningInDevMode
@Deprecated public static boolean isRunningInDevMode()
Deprecated.This method is not needed, since all DEV API Keys start with "DEV".Check if Batch is running in dev mode
NB : if you call this method beforesetConfig(Config), you'll always have the default value : false- Returns:
- true if Batch is running in dev mode, false if not
-
copyBatchExtras
public static void copyBatchExtras(@Nullable android.content.Intent from, @Nullable android.content.Intent to)Copy Batch's internal data from an intent to another. This is useful if you've got an activity that will not get a chance to start Batch before closing itself, but don't want to break features relying on data put in the intent extras, such as direct open tracking or mobile landings.- Parameters:
from- Intent to read Batch's data fromto- Intent to copy Batch's data to
-
copyBatchExtras
public static void copyBatchExtras(@Nullable android.os.Bundle from, @Nullable android.os.Bundle to)Copy Batch's internal data from intent extras to another bundle. This is useful if you've got an activity that will not get a chance to start Batch before closing itself, but don't want to break features relying on data put in the intent extras, such as direct open tracking or mobile landings.- Parameters:
from- Intent to read Batch's data fromto- Intent to copy Batch's data to
-
getBroadcastPermissionName
@NonNull public static java.lang.String getBroadcastPermissionName(@NonNull android.content.Context context)Get the broadcast permission name.Useful if you want to register your broadcast receiver at runtime
-
optOut
public static void optOut(@NonNull android.content.Context context)Opt Out from Batch SDK Usage. Requires Batch to be started.Note that calling the SDK when opted out is discouraged: Some modules might behave unexpectedly when the SDK is opted-out from.
Opting out will: - Prevent
onStart(Activity)oronServiceCreate(Context, boolean)from doing anything at all - Disable any network capability from the SDK - Disable all In-App campaigns - Make the Inbox module return an error immediatly when used - Make the SDK reject any BatchUserProfile orBatchUserDataEditor.save()calls - Make the SDK reject calls toBatch.User.trackEvent(String),Batch.User.trackTransaction(double),Batch.User.trackLocation(Location)and any related methodsEven if you opt in afterwards, data that has been generated while opted out WILL be lost.
If you're also looking at deleting user data, please use
optOutAndWipeData(Context)Note that calling this method will stop Batch, effectively simulating calls to
onStop(Activity),onDestroy(Activity)andonServiceDestroy(Context). Your app should be prepared to handle these cases. Some features might not be disabled until the next app start.
-
optOut
public static void optOut(@NonNull android.content.Context context, @Nullable BatchOptOutResultListener listener)Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
optOut(Context), with a completion listener.Use the listener to be informed about whether the opt-out request has been successfully sent to the server or not. You'll also be able to control what to do in case of failure.
Note: if the SDK has already been opted-out from, this method will instantly call the listener with a *failure* state.
- See Also:
optOut(Context)
-
optOutAndWipeData
public static void optOutAndWipeData(@NonNull android.content.Context context)Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
optOut(Context)but also wipes data.Note that calling this method will stop Batch, effectively simulating calls to
onStop(Activity),onDestroy(Activity)andonServiceDestroy(Context). Your app should be prepared to handle these cases.- See Also:
optOut(Context)
-
optOutAndWipeData
public static void optOutAndWipeData(@NonNull android.content.Context context, @Nullable BatchOptOutResultListener listener)Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
optOut(Context)but also wipes data.Note that calling this method will stop Batch, effectively simulating calls to
onStop(Activity),onDestroy(Activity)andonServiceDestroy(Context). Your app should be prepared to handle these cases.Use the listener to be informed about whether the opt-out request has been successfully sent to the server or not. You'll also be able to control what to do in case of failure.
Note: if the SDK has already been opted-out from, this method will instantly call the listener with a *failure* state.
- See Also:
optOutAndWipeData(Context)
-
optIn
public static void optIn(@NonNull android.content.Context context)Opt In to Batch SDK Usage.This method will be taken into account on next full application start (full process restart)
Only useful if you called
optOut(Context)oroptOutAndWipeData(Context)or opted out by default in the manifestSome features might not be disabled until the next app start if you call this late into the application's life. It is strongly advised to restart the application (or at least the current activity) after opting in.
-
isOptedOut
public static boolean isOptedOut(@NonNull android.content.Context context)Returns whether Batch has been opted out from or notWarning: This method might perform some quick I/O in the caller thread.
-
setFindMyInstallationEnabled
public static void setFindMyInstallationEnabled(boolean enabled)
Control whether Batch should enables the Find My Installation feature (default = true)If enabled Batch will copy the current installation id in the clipboard when the application is foregrounded 5 times within 12 seconds.
- Parameters:
enabled- Whether to enable the find my installation feature.
-
onCreate
public static void onCreate(android.app.Activity activity)
Method to call on your main activityActivity.onCreate(Bundle).- Parameters:
activity- Created activity
-
onStart
public static void onStart(android.app.Activity activity)
Method to call on your main activityActivity.onStart()to start Batch and support URL scheme events.
You must call this method before any other on Batch.
Will fail and log an Error if- Given
activityis null - You call it before calling
setConfig(Config) - Your app doesn't have
android.permission.INTERNETpermission
- Parameters:
activity- The activity that's starting
- Given
-
onServiceCreate
public static void onServiceCreate(android.content.Context context, boolean userActivity)Method to call on your serviceService.onCreate()to start Batch.
You must call this method before any other on Batch.
Note that all Batch functionality is not available in this mode. See the documentation for more info.
Using this method, you'll also be able to control whether this start should count as user activity or not. This might impact Analytics.
Will fail and log an Error if- Given
contextis null - You call it before calling
setConfig(Config) - Your app doesn't have
android.permission.INTERNETpermission
- Parameters:
context- The service or application contextuserActivity- If the start comes from user activity or for background use only
- Given
-
onServiceDestroy
public static void onServiceDestroy(android.content.Context context)
Method to call on your serviceService.onDestroy()to stop Batch.
Calling this method if Batch is already stopped or not started will do nothing
- Parameters:
context- The service or application context
-
onNewIntent
public static void onNewIntent(android.app.Activity activity, android.content.Intent intent)Method to call on your main activityActivity.onNewIntent(Intent)
Calling this method if Batch is already stopped or not started will do nothing- Parameters:
intent-
-
onStop
public static void onStop(android.app.Activity activity)
Method to call on your main activityActivity.onStop()
Calling this method if Batch is already stopped or not started will do nothing- Parameters:
activity- the activity that generate the onStop event
-
onDestroy
public static void onDestroy(android.app.Activity activity)
Method to call on your main activityActivity.onDestroy()
Calling this method if Batch is already stopped or not started will do nothing- Parameters:
activity- the activity that generate the onDestroy event
-
-