Push Notification:Integrate Double Opt-In for Android
Learn to integrate Double Opt-In & Double Opt-Out for Android.
Overview
The Opt-In and Opt-Out API enables developers to integrate user consent management functionality into their Android applications. This ensures user preferences are synced with backend systems for compliance and personalized engagement.
Android Integration Steps
Follow these steps to integrate Opt-In and Opt-Out for Android apps.
Step 1: Disable Auto Asking Notification Permission
Disable the automatic prompt for notification permission by updating the Smartech SDK configuration in your app’s AndroidManifest.xml
file.
<meta-data
android:name="SMT_IS_AUTO_ASK_NOTIFICATION_PERMISSION"
android:value="0" />
The values for Automatic notification permission prompts are:
0
- Disables automatic notification permission prompt.1
- Enables automatic notification permission prompt.
Step 2: Update Double Opt-In URLs and Intervals
Add the required URLs and intervals for double opt-in notifications in your app’s AndroidManifest.xml
file.
<meta-data
android:name="SMT_OPT_IN_1_URL"
android:value="<Add your url for opt-in 1>" />
<meta-data
android:name="SMT_OPT_IN_2_URL"
android:value="<Add your url for opt-in 2>" />
<meta-data
android:name="SMT_OPT_IN_1_INTERVAL"
android:value="2" />
<meta-data
android:name="SMT_OPT_IN_2_INTERVAL"
android:value="5" />
Intervals are measured in days.
Step 3: Initiate Double Opt-In
To trigger the double opt-in flow, integrate the following method at the desired point in your app:
SmartPush.getInstance(new WeakReference<>(this)).initiateNotificationDoubleOptIn();
Step 4 (Optional): Advanced Double Opt-In Controls
Show Double Opt-In Instantly
To display the double opt-in prompt immediately, use the following method:
SmartPush.getInstance(new WeakReference(getContext())).showInstantNotificationDoubleOptIn();
Reset Double Opt-In Intervals
To reset the intervals and re-trigger the double opt-in process, use:
SmartPush.getInstance(new WeakReference(getContext())).resetNotificationDoubleOptIn();
JavaScript Integration Steps
Follow these steps to integrate Opt-In and Opt-Out using JavaScript.
1. Include Smartech SDK
Add the Smartech SDK script to your push notification double opt-in HTML:
<script src="https://cdnt.netcoresmartech.com/smartech-app-sdk/scripts/dev/smartech-app-sdk.js?v=1.0.0"></script>
<script>
SmartechAppSDK.init();
</script>
2. Add Data Attributes for Button Actions
Integrate the following data attributes into your buttons to enable different opt-in actions.
Attribute Name | Functionality |
---|---|
SMTPushNotificationDoubleOptIn | Opens the system notification permission prompt. |
SMTPushNotificationDoubleOptOut | Handles functionality to redirect users to system settings for notification permissions. |
SMTOpenAppDeviceSettings | Navigate the user directly to the app's device settings page. |
3. Button Implementation
Assign Opt-In to Buttons
<button class="buttons btn-allow" data-smt-action="SMTPushNotificationDoubleOptIn">Allow</button>
Assign Opt-Out to Buttons
<button class="buttons btn-deny" data-smt-action="SMTPushNotificationDoubleOptOut">Not now</button>
Assign Navigate to Settings to Buttons
<button class="buttons btn-allow" data-smt-action="SMTOpenAppDeviceSettings">Go to settings</button>
Sample Prompts
Updated about 1 month ago