### Complete PushAlert SDK Integration Example Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Initialize and configure the PushAlert SDK with all common settings in an Application class. Ensure to replace 'YOUR_APP_ID-XXXXXX-XXXX' with your actual App ID. This example demonstrates setting up notification appearance, behavior, analytics, location sharing, custom opt-in dialogs, and event listeners. ```java import android.app.Application; import android.os.Build; import android.util.Log; import org.json.JSONException; import org.json.JSONObject; import co.pushalert.NotificationOpener; import co.pushalert.NotificationReceiver; import co.pushalert.PANotification; import co.pushalert.PANotificationOpened; import co.pushalert.PASubscribe; import co.pushalert.PushAlert; import co.pushalert.TwoStepHelper; public class MyApplication extends Application { private static final String TAG = "PushAlert"; @Override public void onCreate() { super.onCreate(); // Enable debug mode for development PushAlert.enableDebug(BuildConfig.DEBUG); // Initialize PushAlert PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) // Notification appearance .setDefaultSmallIcon(R.drawable.ic_notification) .setDefaultAccentColor(R.color.colorPrimary) // Behavior settings .setOptInDelay(5000) .unsubscribeWhenNotificationsAreDisabled(false) .setInAppNotificationBehaviour(PushAlert.PAInAppBehaviour.NOTIFICATION) // Analytics .enableFirebaseEventReporting(true) // Location (requires permission) .enableLocationSharing(true) // Custom two-step dialog .customizeTwoStep(new TwoStepHelper() { @Override public void setValues() { title = "Never Miss an Update!"; subTitle = "Get notified about orders, deals, and personalized recommendations."; acceptBtn = "Enable Notifications"; rejectBtn = "Not Now"; acceptBtnBgColor = R.color.colorPrimary; } }) // Subscription listener .setOnSubscribeListener(new PASubscribe() { @Override public void onSubscribe(String subscriberId) { Log.d(TAG, "Subscribed with ID: " + subscriberId); // Sync with your backend sendSubscriberIdToServer(subscriberId); } }) // Custom notification receiver .setNotificationReceiver(new NotificationReceiver() { @Override public boolean notificationReceived() { PANotification notification = getPANotification(); Log.d(TAG, "Received: " + notification.getShortTitle()); // Return false to display notification return false; } }) // Custom notification opener .setNotificationOpener(new NotificationOpener() { @Override public void notificationOpened(PANotificationOpened data) { handleNotificationClick(data); } }); // Set opt-in mode based on Android version if (Build.VERSION.SDK_INT >= 33) { PushAlert.setOptInMode(PushAlert.PAOptInMode.TWO_STEP); } else { PushAlert.setOptInMode(PushAlert.PAOptInMode.AUTO); } } private void sendSubscriberIdToServer(String subscriberId) { // Implement your backend sync logic } private void handleNotificationClick(PANotificationOpened data) { // Implement your navigation logic } } ``` -------------------------------- ### Initialize PushAlert SDK Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Initialize the SDK in your Application class. Enable debug logging and configure default settings like accent color and small icon. Set up a listener for subscription events and define the opt-in mode. ```java import android.app.Application; import android.os.Build; import co.pushalert.PASubscribe; import co.pushalert.PushAlert; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); // Enable debug logging during development PushAlert.enableDebug(true); // Initialize PushAlert with your App ID from dashboard PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setDefaultAccentColor(R.color.notification_accent) .setDefaultSmallIcon(R.drawable.ic_notification) .enableFirebaseEventReporting(true) .unsubscribeWhenNotificationsAreDisabled(false) .setOptInDelay(3000) // 3 second delay before showing opt-in .setOnSubscribeListener(new PASubscribe() { @Override public void onSubscribe(String subscriberId) { // Store subscriber ID in your backend Log.d("PushAlert", "Subscribed: " + subscriberId); } }); // Set opt-in mode based on Android version if (Build.VERSION.SDK_INT >= 33) { // Android 13+ requires explicit permission PushAlert.setOptInMode(PushAlert.PAOptInMode.TWO_STEP); } else { PushAlert.setOptInMode(PushAlert.PAOptInMode.AUTO); } } } ``` -------------------------------- ### Configure Opt-In Modes Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Set the desired opt-in mode for requesting notification permissions. AUTO subscribes automatically, TWO_STEP shows a custom dialog first, and MANUAL requires explicit developer control. ```java // AUTO Mode - Subscribes automatically when possible PushAlert.setOptInMode(PushAlert.PAOptInMode.AUTO); ``` ```java // TWO_STEP Mode - Shows a custom opt-in dialog before system permission PushAlert.setOptInMode(PushAlert.PAOptInMode.TWO_STEP); ``` ```java // MANUAL Mode - Full developer control over when to request permission PushAlert.setOptInMode(PushAlert.PAOptInMode.MANUAL); ``` ```java // Request permission manually (returns true if already subscribed) boolean alreadySubscribed = PushAlert.requestForPushNotificationPermission(false); if (alreadySubscribed) { // User is already subscribed showMessage("Already receiving notifications!"); } ``` ```java // Direct permission request (one-step, opens settings if disabled) PushAlert.requestForPushNotificationPermission(true); ``` -------------------------------- ### Implement Custom Notification Opener Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Use this to define custom navigation or actions when a user interacts with a notification. Requires handling JSON data and potential exceptions. ```java import co.pushalert.NotificationOpener; import co.pushalert.PANotificationOpened; PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setNotificationOpener(new NotificationOpener() { @Override public void notificationOpened(PANotificationOpened paNotificationOpened) { long notificationId = paNotificationOpened.getNotificationId(); String url = paNotificationOpened.getUrl(); String actionId = paNotificationOpened.getActionId(); JSONObject extraData = paNotificationOpened.getExtraData(); try { // Handle based on action button clicked if (actionId.equals("main")) { // Main notification body was clicked } else if (actionId.equals("view_order")) { // "View Order" action button clicked String orderId = extraData.getString("order_id"); openOrderDetails(orderId); return; } else if (actionId.equals("dismiss")) { // Dismiss button clicked return; } // Handle based on extra data if (extraData.has("screen")) { String screen = extraData.getString("screen"); switch (screen) { case "product": String productId = extraData.getString("product_id"); openProductScreen(productId); break; case "category": String categoryId = extraData.getString("category_id"); openCategoryScreen(categoryId); break; case "order": String orderId = extraData.getString("order_id"); openOrderDetails(orderId); break; default: openMainActivity(); } } else if (url != null && !url.isEmpty()) { // Open URL in browser or WebView openUrl(url); } else { openMainActivity(); } } catch (JSONException e) { openMainActivity(); } } }); ``` -------------------------------- ### Report Simple Conversion Events Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Log conversion events without an associated monetary value, such as user registrations or sign-ups. ```java public void onUserRegistration() { PushAlert.reportConversion("Registration"); } ``` ```java public void onNewsletterSignup() { PushAlert.reportConversion("Newsletter_Signup"); } ``` ```java public void onTrialStarted() { PushAlert.reportConversion("Trial_Started"); } ``` ```java public void onAppRated() { PushAlert.reportConversion("App_Rated"); } ``` -------------------------------- ### Add Out of Stock Alert Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Enable users to subscribe for back-in-stock notifications. Requires product ID, variant ID, last known price, and optional product information. ```java int productId = 2432; int variantId = 1; // Specific size/color variant, use 0 if none double lastKnownPrice = 19.99; Map productInfo = new HashMap<>(); productInfo.put("product_name", "Running Shoes - Size 10"); productInfo.put("product_url", "https://yourstore.com/products/running-shoes?size=10"); productInfo.put("customer_name", "John"); PushAlert.addOutOfStockAlert(productId, variantId, lastKnownPrice, productInfo); ``` -------------------------------- ### Initialize PushAlert with Custom Notification Receiver Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Initialize the SDK and set a custom receiver to intercept and modify incoming notifications. Return true from `notificationReceived` to suppress default display. ```java import co.pushalert.NotificationReceiver; import co.pushalert.PANotification; PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setNotificationReceiver(new NotificationReceiver() { @Override public boolean notificationReceived() { PANotification notification = getPANotification(); // Access notification properties String title = notification.getShortTitle(); String content = notification.getContent(); String url = notification.getUrl(); JSONObject extraData = notification.getExtraData(); // Modify notification content notification.setShortTitle("New: " + title); notification.setAccentColor("#FF5722"); // Handle extra data for custom logic try { if (extraData.has("silent") && extraData.getBoolean("silent")) { // Process silently without showing notification processDataInBackground(extraData); return true; // Return true to suppress notification display } if (extraData.has("category")) { String category = extraData.getString("category"); // Customize based on category if (category.equals("promo")) { notification.setChannel("promotions_channel"); } } } catch (JSONException e) { e.printStackTrace(); } return false; // Return false to show the notification } }); ``` -------------------------------- ### Enable Location-Based Targeting Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Configure location sharing and handle runtime permissions for Android 6.0+. Ensure the appropriate manifest permissions are declared. ```java // In AndroidManifest.xml, add permission: // // or // // Enable location sharing during initialization PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .enableLocationSharing(true); // Request location permission at runtime (Android 6.0+) private void requestLocationPermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE); } } ``` -------------------------------- ### Add Price Drop Alert Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Subscribe users to price drop notifications for a specific product. Requires product ID, variant ID, current price, and optional product metadata. ```java int productId = 2431; int variantId = 1; // Use 0 if no variants double currentPrice = 49.99; Map productExtras = new HashMap<>(); productExtras.put("product_name", "Wireless Headphones"); productExtras.put("product_url", "https://yourstore.com/products/wireless-headphones"); productExtras.put("image_url", "https://yourstore.com/images/headphones.jpg"); PushAlert.addPriceDropAlert(productId, variantId, currentPrice, productExtras); ``` -------------------------------- ### Customize Two-Step Opt-In Dialog Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Customize the appearance and text of the two-step opt-in dialog. This includes setting titles, subtitles, button text, colors, and icons. ```java import co.pushalert.TwoStepHelper; PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .customizeTwoStep(new TwoStepHelper() { @Override public void setValues() { // Customize text title = "Stay Updated!"; subTitle = "Get instant updates on orders, deals, and more."; acceptBtn = "Yes, Notify Me"; rejectBtn = "Maybe Later"; // Customize colors (use your color resources) bgColor = R.color.dialog_background; titleTextColor = R.color.dialog_title; subTitleTextColor = R.color.dialog_subtitle; acceptBtnTextColor = R.color.white; acceptBtnBgColor = R.color.primary; rejectBtnTextColor = R.color.gray; rejectBtnBgColor = R.color.transparent; // Customize icons iconDrawable = R.drawable.ic_bell; imageDrawable = R.drawable.notification_preview; } }); ``` -------------------------------- ### Set Subscriber Attributes Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Use built-in methods for common attributes like name, email, and age, or add custom key-value pairs. Associate a user ID for cross-platform identification. ```java // Built-in attribute methods for common fields PushAlert.setFirstName("John"); PushAlert.setLastName("Doe"); PushAlert.setEmail("john.doe@example.com"); PushAlert.setAge(28); PushAlert.setGender("male"); PushAlert.setPhoneNum("+1-555-123-4567"); // Associate with your user ID for cross-platform identification PushAlert.associateID("user_12345"); // Add custom attributes as key-value pairs Map customAttributes = new HashMap<>(); customAttributes.put("plan_type", "premium"); customAttributes.put("signup_date", "2024-01-15"); customAttributes.put("preferred_category", "electronics"); customAttributes.put("zip_code", "98125"); customAttributes.put("loyalty_points", "2500"); PushAlert.addAttributes(customAttributes); ``` -------------------------------- ### Report Purchase Conversion Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Track purchase events with a monetary value to measure campaign effectiveness. ```java public void onPurchaseComplete(double orderTotal) { PushAlert.reportConversionWithValue("Purchase", orderTotal); } ``` -------------------------------- ### Check Price Drop Alert Status Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Verify if a price drop alert is already enabled for a given product and variant. ```java if (PushAlert.isPriceDropEnabled(productId, variantId)) { // Show "Remove Alert" button instead btnPriceDrop.setText("Remove Price Alert"); } ``` -------------------------------- ### Check Out of Stock Alert Status Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Determine if an out-of-stock alert has already been set for a product variant. ```java if (PushAlert.isOutOfStockEnabled(productId, variantId)) { notifyMeButton.setEnabled(false); notifyMeButton.setText("Alert Set"); } ``` -------------------------------- ### Trigger Custom Events Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Track user interactions and behaviors by triggering custom events. Events can include category, action, label, and a numeric value for detailed tracking. ```java // Full event with category, action, label, and numeric value PushAlert.triggerEvent("videos", "play", "tutorial_getting_started", 1); // Event with category, action, and label PushAlert.triggerEvent("products", "view", "SKU-12345"); // Event with category and action only PushAlert.triggerEvent("checkout", "initiated"); ``` ```java // Examples of common events public void onVideoPlay(String videoId, int durationSeconds) { PushAlert.triggerEvent("videos", "play", videoId, durationSeconds); } public void onProductView(String productId) { PushAlert.triggerEvent("products", "view", productId); } public void onSearch(String searchQuery) { PushAlert.triggerEvent("search", "query", searchQuery); } public void onAddToWishlist(String productId) { PushAlert.triggerEvent("wishlist", "add", productId); } ``` -------------------------------- ### In-App Notification Behavior Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Configuration methods to control how notifications appear when the application is running in the foreground. ```APIDOC ## In-App Notification Behavior ### Description Configures the SDK to either display or suppress notifications while the app is in the foreground. ### Configuration - **PushAlert.init(...).setInAppNotificationBehaviour(PushAlert.PAInAppBehaviour.NOTIFICATION)**: Enables foreground notifications. - **PushAlert.init(...).setInAppNotificationBehaviour(PushAlert.PAInAppBehaviour.NONE)**: Suppresses foreground notifications. ``` -------------------------------- ### Manage User Segments Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Add or remove subscribers from segments defined in the PushAlert dashboard. This is crucial for targeted notification campaigns. ```java // Add user to a segment (segment ID from PushAlert dashboard) int premiumUsersSegment = 20577; PushAlert.addUserToSegment(premiumUsersSegment); // Add to multiple segments PushAlert.addUserToSegment(20578); // "Active Users" segment PushAlert.addUserToSegment(20579); // "Newsletter Subscribers" segment // Remove user from a segment PushAlert.removeUserFromSegment(20577); ``` ```java // Example: Segment based on user actions public void onUserPurchase(String category) { if (category.equals("electronics")) { PushAlert.addUserToSegment(ELECTRONICS_BUYERS_SEGMENT); } else if (category.equals("fashion")) { PushAlert.addUserToSegment(FASHION_BUYERS_SEGMENT); } } ``` -------------------------------- ### Configure In-App Notification Behavior Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Control whether notifications are displayed when the app is in the foreground. Set to NOTIFICATION to show them, or NONE to suppress them. ```java PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setInAppNotificationBehaviour(PushAlert.PAInAppBehaviour.NOTIFICATION); ``` ```java PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setInAppNotificationBehaviour(PushAlert.PAInAppBehaviour.NONE); ``` -------------------------------- ### Manage Abandoned Cart Notifications Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Track cart activity to trigger abandoned cart recovery campaigns. Update cart data when items are added/removed, and delete when the cart is emptied or checkout completes. ```java // Update abandoned cart when items are added public void updateCart(List items, double totalAmount) { if (items.isEmpty() || totalAmount == 0) { // Delete cart data when empty PushAlert.processAbandonedCart(PushAlert.AbandonedCartAction.DELETE, null); } else { // Update cart data for abandoned cart notifications Map cartData = new HashMap<>(); cartData.put("customer_name", "John Doe"); cartData.put("total_items", String.valueOf(items.size())); cartData.put("total_amount", String.valueOf(totalAmount)); cartData.put("cart_url", "https://yourstore.com/cart/"); cartData.put("checkout_url", "https://yourstore.com/checkout/"); cartData.put("image", items.get(0).getImageUrl()); // First item image cartData.put("currency", "USD"); PushAlert.processAbandonedCart(PushAlert.AbandonedCartAction.UPDATE, cartData); } } ``` ```java // Clear cart data on successful purchase public void onCheckoutComplete() { PushAlert.processAbandonedCart(PushAlert.AbandonedCartAction.DELETE, null); PushAlert.reportConversionWithValue("Purchase", orderTotal); } ``` -------------------------------- ### Manage Privacy Consent Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Control notification enablement based on user consent status for GDPR compliance. Use these methods to check, set, and update consent state. ```java // Check if privacy consent is required boolean requiresConsent = PushAlert.getRequiresPrivacyConsent(); // Set privacy consent requirement during initialization PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .setRequiresPrivacyConsent(true); // Get current privacy consent status boolean hasConsent = PushAlert.getUserPrivacyConsent(); // Set user privacy consent (call after user accepts privacy policy) public void onPrivacyPolicyAccepted() { PushAlert.setUserPrivacyConsent(true); } public void onPrivacyPolicyRejected() { PushAlert.setUserPrivacyConsent(false); } ``` -------------------------------- ### Remove Out of Stock Alert Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Cancel an out-of-stock notification subscription for a specific product variant. ```java PushAlert.removeOutOfStockAlert(productId, variantId); ``` -------------------------------- ### Manage User Subscription Status Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Check if a user is subscribed, retrieve their subscriber ID, and programmatically enable or disable notifications. Configure auto-unsubscribe behavior when app notifications are disabled in system settings. ```java boolean isSubscribed = PushAlert.isUserSubscribed(); ``` ```java String subscriberId = PushAlert.getSubscriberID(); if (subscriberId != null) { // User is subscribed, sync with your backend syncSubscriberWithBackend(subscriberId); } ``` ```java boolean notificationsDisabled = PushAlert.isNotificationDisabled(); ``` ```java PushAlert.disableNotification(true); // Disable ``` ```java PushAlert.disableNotification(false); // Re-enable ``` ```java PushAlert.init("YOUR_APP_ID-XXXXXX-XXXX", getApplicationContext()) .unsubscribeWhenNotificationsAreDisabled(true); ``` -------------------------------- ### Subscription Status Management Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Methods to check if a user is subscribed, retrieve the unique subscriber ID, and manage notification toggles. ```APIDOC ## Subscription Status Management ### Description Methods to verify user subscription status, retrieve the subscriber ID for backend synchronization, and toggle notification states. ### Methods - **PushAlert.isUserSubscribed()**: Returns boolean indicating subscription status. - **PushAlert.getSubscriberID()**: Returns String subscriber ID or null if not subscribed. - **PushAlert.isNotificationDisabled()**: Returns boolean indicating if notifications are disabled. - **PushAlert.disableNotification(boolean)**: Enables or disables notifications programmatically. - **PushAlert.init(...).unsubscribeWhenNotificationsAreDisabled(boolean)**: Configures auto-unsubscribe behavior. ``` -------------------------------- ### Remove Price Drop Alert Source: https://context7.com/inkwired/pushalert-android-sdk/llms.txt Unsubscribe users from price drop notifications for a specific product and variant. ```java PushAlert.removePriceDropAlert(productId, variantId); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.