Class Batch
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Batch Action managerstatic final class
Batch Debug modulestatic final class
Batch EventDispatcher modulestatic final class
Batch Inbox modulestatic final class
Batch Messaging modulestatic final class
Batch Profile modulestatic final class
Batch Push modulestatic final class
Batch User module -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Intent broadcasted locally by the SDK when a push registration identifier has been retrieved (also called "Push Token").static final String
Permission suffix for broadcasts triggered by Batch.static final String
Extra containing the Registration Identifier for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcaststatic final String
Extra containing the Registration Provider name for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcaststatic final String
Extra containing the Sender ID (if any) for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcaststatic final String
Notification tag. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyBatchExtras
(Intent from, Intent to) Copy Batch's internal data from an intent to another.static void
copyBatchExtras
(Bundle from, Bundle to) Copy Batch's internal data from intent extras to another bundle.static void
disableMigration
(EnumSet<BatchMigration> migrations) Set data migrations you want to disable.static String
getBroadcastPermissionName
(Context context) Get the broadcast permission name.static String
Get the id of the current session, random uuid used internally by Batch to identify the app session.static boolean
isOptedOut
(Context context) Returns whether Batch has been opted out from or notstatic void
Method to call on your main activityActivity#onCreate(Bundle)
.static void
Method to call on your main activityActivity#onDestroy()
Calling this method if Batch is already stopped or not started will do nothingstatic void
onNewIntent
(Activity activity, 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 void
onServiceCreate
(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 void
onServiceDestroy
(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 void
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 Givenactivity
is null You call it before callingBatch#start(String)
Your app doesn't haveandroid.permission.INTERNET
permissionstatic void
Method to call on your main activityActivity#onStop()
Calling this method if Batch is already stopped or not started will do nothingstatic void
Opt In to Batch SDK Usage.static void
Opt Out from Batch SDK Usage.static void
optOut
(Context context, BatchOptOutResultListener listener) Opt Out from Batch SDK Usage.static void
optOutAndWipeData
(Context context) Opt Out from Batch SDK Usage.static void
optOutAndWipeData
(Context context, BatchOptOutResultListener listener) Opt Out from Batch SDK Usage.static void
setFindMyInstallationEnabled
(boolean enabled) Control whether Batch should enables the Find My Installation feature (default = true)static void
setLoggerDelegate
(LoggerDelegate delegate) Set if Batch should send its logs to an object of yours (default = null)
Be careful with your implementation: setting this can impact stability and performance
You should only use it if you know what you are doing.static void
setLoggerLevel
(LoggerLevel level) Set the log level that Batch should usestatic void
Set the API Key of Batch.
You should call this method before any other, only one time.
Typically on the onCreate of your Application class.static void
Configure the SDK Automatic Data Collection.
-
Field Details
-
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_NAME
andEXTRA_REGISTRATION_IDENTIFIER
string extras.- See Also:
-
BROADCAST_PERMISSION_SUFFIX
Permission suffix for broadcasts triggered by Batch. The actual permission is your package name + BROADCAST_PERMISSION_SUFFIXYou can call
getBroadcastPermissionName(android.content.Context)
to get the full permission name.- See Also:
-
EXTRA_REGISTRATION_IDENTIFIER
Extra containing the Registration Identifier for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcast- See Also:
-
EXTRA_REGISTRATION_PROVIDER_NAME
Extra containing the Registration Provider name for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcast- See Also:
-
EXTRA_REGISTRATION_SENDER_ID
Extra containing the Sender ID (if any) for aACTION_REGISTRATION_IDENTIFIER_OBTAINED
broadcast- See Also:
-
NOTIFICATION_TAG
Notification tag.Notifications displayed by Batch all have this tag. Useful if you need to cancel them, for example.
- See Also:
-
-
Method Details
-
start
Set the API Key of Batch.
You should call this method before any other, only one time.
Typically on the onCreate of your Application class.- Parameters:
apiKey
- Your Batch API Key
-
disableMigration
Set data migrations you want to disable.- Parameters:
migrations
- EnumSet of Migrations to disable. SeeBatchMigration
-
setLoggerDelegate
Set if Batch should send its logs to an object of yours (default = null)
Be careful with your implementation: setting this can impact stability and performance
You should only use it if you know what you are doing.- Parameters:
delegate
- An object implementingLoggerDelegate
-
setLoggerLevel
Set the log level that Batch should use- Parameters:
level
- The level of the logger to use
-
updateAutomaticDataCollection
Configure the SDK Automatic Data Collection.- Parameters:
editor
- A callback which will be called with an instance of the data collection config. Once your callback ends, Batch will persist the changes.
-
getSessionID
Get the id of the current session, random uuid used internally by Batch to identify the app session.- Returns:
- session id if any, null otherwise
-
copyBatchExtras
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
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
Get the broadcast permission name.Useful if you want to register your broadcast receiver at runtime
-
optOut
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
Batch#onStart(Activity)
orBatch#onServiceCreate(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 immediately when used - Make the SDK reject any BatchUserProfile orBatchProfileAttributeEditor#save()
calls - Make the SDK reject calls toBatch.Profile#trackEvent(String)
,Batch.Profile#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
Batch#optOutAndWipeData(Context)
Note that calling this method will stop Batch, effectively simulating calls to
Batch#onStop(Activity)
,Batch#onDestroy(Activity)
andBatch#onServiceDestroy(Context)
. Your app should be prepared to handle these cases. Some features might not be disabled until the next app start. -
optOut
Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
Batch#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:
-
optOutAndWipeData
Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
Batch#optOut(Context)
but also wipes data.Note that calling this method will stop Batch, effectively simulating calls to
Batch#onStop(Activity)
,Batch#onDestroy(Activity)
andBatch#onServiceDestroy(Context)
. Your app should be prepared to handle these cases.- See Also:
-
optOutAndWipeData
Opt Out from Batch SDK Usage. Requires Batch to be started.Same as
Batch#optOut(Context)
but also wipes data.Note that calling this method will stop Batch, effectively simulating calls to
Batch#onStop(Activity)
,Batch#onDestroy(Activity)
andBatch#onServiceDestroy(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:
-
optIn
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
Batch#optOut(Context)
orBatch#optOutAndWipeData(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
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
Method to call on your main activityActivity#onCreate(Bundle)
.- Parameters:
activity
- Created activity
-
onStart
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
activity
is null - You call it before calling
Batch#start(String)
- Your app doesn't have
android.permission.INTERNET
permission
- Parameters:
activity
- The activity that's starting
- Given
-
onServiceCreate
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
context
is null - You call it before calling
Batch#start(String)
- Your app doesn't have
android.permission.INTERNET
permission
- Parameters:
context
- The service or application contextuserActivity
- If the start comes from user activity or for background use only
- Given
-
onServiceDestroy
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
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
- Android's intent
-
onStop
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
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
-