How to track push on mobile without using PushWooshService?

Comments

1 comment

  • Avatar
    Justix

    Hi there I had discussion with Vitaly from Push Woosh Team and he explained me how to handle my issue:

    We can create our own Receiver to catch Push Clicks and send tracking to PushWoosh Dashboard by ourself

     public class NotificationReceiver extends BroadcastReceiver
        {
            public void onReceive(Context context, Intent intent)
            {
                if (intent == null)
                    return;
    
                //Let Pushwoosh SDK to pre-handling push (Pushwoosh track stats, opens rich pages, etc.).
                //It will return Bundle with a push notification data
                Bundle pushBundle = PushManagerImpl.preHandlePush(context, intent);
                if(pushBundle == null)
                    return;
    
                //get push bundle as JSON object
                JSONObject dataObject = PushManagerImpl.bundleToJSON(pushBundle);
    
                //Get default launcher intent for clarity
                Intent launchIntent  = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
                launchIntent.addCategory("android.intent.category.LAUNCHER");
    
                launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    
                //Put push notifications payload in Intent
                launchIntent.putExtras(pushBundle);
                launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString());
    
                //Start activity!
                context.startActivity(launchIntent);
    
                //Let Pushwoosh SDK post-handle push (track stats, etc.)
                PushManagerImpl.postHandlePush(context, intent);
            }
        }
    

    <receiverandroid:name="your.app.package.notificationreceiver"/> <meta-data android:name="PW_NOTIFICATION_RECEIVER" android:value="${notificationReceiverPackage}.NotificationReceiver"/>

Please sign in to leave a comment.