{"_id":"56e527ad75eb791700a9c4c4","__v":51,"githubsync":"","user":"56cecbb2e50c9c1b008303eb","parentDoc":null,"project":"56cecbdb44c5700b0095c03a","version":{"_id":"56cecbdc44c5700b0095c03d","project":"56cecbdb44c5700b0095c03a","__v":10,"createdAt":"2016-02-25T09:39:40.121Z","releaseDate":"2016-02-25T09:39:40.121Z","categories":["56cecbdc44c5700b0095c03e","56d1d2c05ad7ad0b00b7e809","56d1d2fa5ad7ad0b00b7e80a","56d369331660770b00081159","56d3693d1660770b0008115a","56e5361e7990160e002e3fbc","56e5362775eb791700a9c4d2","57a9030947f2f419009188d4","57b4705ee9e4c60e00f6f4c3","5828f5b04774ab0f005179a2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"56d369331660770b00081159","__v":5,"project":"56cecbdb44c5700b0095c03a","pages":["56d403d87e7f160b00cd10a8","56e51bf22d90970e00af1b18","56e527ad75eb791700a9c4c4","56e538732d90970e00af1b28","56e6941a0d2f0f0e009326b0"],"version":"56cecbdc44c5700b0095c03d","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-28T21:40:03.218Z","from_sync":false,"order":1,"slug":"android","title":"Android"},"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-13T08:41:17.135Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"The following instructions will help you integrate the PushApps SDK, with your current external push provider. Please choose your one:\n* [Urabn Airship](#urban-airship)\n* [PushWoosh](#pushwoosh)\n* [Azure](#azure)\n* [Phonegap plugin (com.phonegap.plugins.PushPlugin)](#phonegap-plugin)\n* [Localytics](#localytics)\n* [Parse](#parse)\n* [Adobe Phonegap Plugin](#adobe-phonegap-plugin)\n* [Mixpanel](#mixpanel)\n* [OneSignal](#onesignal)\n* [PushBots](#pushbots)\n* [Swrve](#swrve)\n* [Custom Push Provider](#custom-push-provider)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Urban Airship\"\n}\n[/block]\n1. Copy the following code to a new file called PushAppsCustomNotificationFactory.java and add it to your project (don't forget to change the package name as needed):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package mobi.pushapps.demo.urbanairship;\\n\\nimport android.app.Notification;\\nimport android.content.Context;\\nimport android.content.Intent;\\n\\nimport com.urbanairship.push.PushMessage;\\nimport com.urbanairship.push.notifications.NotificationFactory;\\nimport com.urbanairship.util.NotificationIdGenerator;\\n\\nimport mobi.pushapps.PABuildNotificationListener;\\nimport mobi.pushapps.PushApps;\\nimport mobi.pushapps.models.PANotification;\\nimport mobi.pushapps.utils.PALogger;\\n\\n/**\\n * Created by Asaf Ron on 31/03/16.\\n */\\npublic class PushAppsCustomNotificationFactory extends NotificationFactory {\\n\\n    public PushAppsCustomNotificationFactory(Context context) {\\n        super(context);\\n    }\\n\\n    :::at:::Override\\n    public Notification createNotification(PushMessage message, int notificationId) {\\n        String paCampaignId = \\\"\\\";\\n        String paUrl = \\\"\\\";\\n        String paImageUrl = \\\"\\\";\\n\\n        try {\\n            paCampaignId = message.getPushBundle().getString(\\\"pa_c\\\");\\n        } catch (Exception e) {\\n            PALogger.logError(\\\"Could not get pa campaign id: \\\" + e.getLocalizedMessage());\\n        }\\n\\n        try {\\n            paUrl = message.getPushBundle().getString(\\\"pa_u\\\");\\n        } catch (Exception e) {\\n            PALogger.logError(\\\"Could not get pa url: \\\" + e.getLocalizedMessage());\\n        }\\n\\n        try {\\n            paImageUrl = message.getPushBundle().getString(\\\"pa_i\\\");\\n        } catch (Exception e) {\\n            PALogger.logError(\\\"Could not get pa image url: \\\" + e.getLocalizedMessage());\\n        }\\n\\n        PANotification notification = new PANotification.Builder()\\n                .text(message.getAlert())\\n                .campaignId(paCampaignId) // optional, replace with campaign id\\n                .title(message.getTitle()) // optional, replace with a custom title\\n                .url(paUrl) // optinal, replace with main url of the notification\\n                .imageUrl(paImageUrl) // optinal, replace with main image url\\n                .build();\\n        PushApps.buildNotification(this.getContext(), message.getPushBundle(), notification, new\\n                PANotificationListener() {\\n                    @Override\\n\\t\\t\\t\\t\\t\\tpublic void onMessageReceived(Context context, Bundle bundle) {\\n                        PALogger.logError(\\\"Could not show enriched notification\\\");\\n                    }\\n                });\\n\\n        return null;\\n    }\\n\\n    @Override\\n    public int getNextId(PushMessage pushMessage) {\\n        return NotificationIdGenerator.nextID();\\n    }\\n\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n3. In your application class, after registering to Urban Airship, paste the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"UAirship.shared().getPushManager().setNotificationFactory(new PushAppsCustomNotificationFactory(this));\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n4. Continue to Step 5 in the [Android SDK Installation (Android Studio / Eclipse)](doc:sdk-installation-eclipse)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"PushWoosh\"\n}\n[/block]\n### Native SDK\n1. If you implemented PushWoosh through gradle, please add the following code inside `OnCreate` method inside your `Appliction` class:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\n    public void onCreate() {\\n        super.onCreate();\\n\\n        PushApps.register(this); // Register device to PushApps\\n        PushApps.setNotificationListener(this, new PANotificationListener() {\\n\\n            @Override\\n            public void onMessageReceived(Context context, Bundle bundle) {\\n                Bundle extras = bundle;\\n\\n                String campaignId = null;\\n                String image = null;\\n                String url = null;\\n\\n                if (extras != null) {\\n                    url = extras.getString(\\\"l\\\");\\n                    if (url != null) {\\n                        extras.remove(\\\"l\\\");\\n                        extras.putString(\\\"ll\\\", url);\\n                    }\\n                    if (extras.containsKey(\\\"pa_c\\\")) {\\n                        campaignId = extras.getString(\\\"pa_c\\\");\\n                    }\\n                    if (extras.containsKey(\\\"pa_i\\\")) {\\n                        image = extras.getString(\\\"pa_i\\\");\\n                    }\\n                    if (extras.containsKey(\\\"pa_u\\\")) {\\n                        url = extras.getString(\\\"pa_u\\\");\\n                    }\\n                }\\n\\n                String notificationMessage = extras.getString(\\\"title\\\");\\n                String notificationTitle = extras.getString(\\\"header\\\") != null ? extras.getString(\\\"header\\\") : PADeviceUtils.getApplicationName(getApplicationContext());\\n                String notificationImage = image;\\n                String notificationSound = extras.getString(\\\"s\\\");\\n                String notificationUrl = url;\\n\\n                PANotification notification = new PANotification.Builder()\\n                        .campaignId(campaignId)\\n                        .text(notificationMessage)\\n                        .sound(notificationSound)\\n                        .title(notificationTitle)\\n                        .url(notificationUrl)\\n                        .imageUrl(notificationImage)\\n                        .build();\\n                PushApps.buildNotification(getApplicationContext(), extras, notification, null);\\n\\n            }\\n        });\\n    }\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. Continue to Step 5 in the [Android SDK Installation (Android Studio / Eclipse)](doc:sdk-installation-eclipse) \n\n\n### Phonegap plugin\n1. Please make sure you have the latest PushWoosh Cordova plugin. If you're not sure, you can execute the following commands in your terminal:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ cordova plugin rm pushwoosh-cordova-plugin\\n$ cordova plugin add pushwoosh-cordova-plugin\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n2. Add PushApps plugin by executing the following command (Replace YOUR--PUSHAPPS--SDK--KEY with your PushApps SDK Key):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ cordova plugin add https://github.com/PushAppsPlatform/pushwoosh-cordova-pushapps-plugin-rtl.git --variable PA_SDK_KEY=YOUR--PUSHAPPS--SDK--KEY\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n*Handle user clicks on notifications:*\nIn your `push-notification` event listener method, the clicked recommendation URL will appear in:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var pushappsArticle = event.notification.PAArticleUrl;\\nif (pushappsArticle) {\\n\\t\\t// Go to the PushApps Clicked content\\n} else {\\n\\t\\t// Do what you’re doing today, open your main notification content\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Azure\"\n}\n[/block]\n1. In your class that extends `com.microsoft.windowsazure.notifications.NotificationsHandler`, please add the following lines, inside the `onReceive` method, instead of executing your original notification building code flow:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PANotification notification = new PANotification.Builder()\\n    .text(NOTIFICATION_MESSAGE)\\n    .campaignId(THE_CAMPAIGN_ID) // optional, replace with campaign id  \\n    .sound(NOTIFICATION_SOUND) // optional, replace with your sound file name\\n    .title(NOTIFICATION_TITLE) // optional, replace with a custom title\\n    .url(NOTIFICATION_URI) // optinal, replace with main url of the notification\\n    .imageUrl(NOTIFICATION_IMAGE_URL) // optinal, replace with main image url\\n    .build();\\nPushApps.buildNotification(context, bundle, notification, new \\t \\n         PANotificationListener() {\\n               @Override\\n               public void onMessageReceived(Context context, Bundle bundle) {\\n                               // This block code will be executed if no \\n                               // enrichment can be shown at the moment. \\n                               // Please execute your “old” push notification \\n                               // code here.\\n               }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Phonegap Plugin (com.phonegap.plugins.PushPlugin)\"\n}\n[/block]\n1. Remove your current plugin installation:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ cordova plugin rm com.phonegap.plugins.PushPlugin\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n2. Add the updated plugin to your application (Replace YOUR--PUSHAPPS--SDK--KEY with your PushApps SDK Key):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ cordova plugin add https://github.com/asafron/PushPlugin.git --variable PA_SDK_KEY=<YOUR_PUSHAPPS_SDK_KEY>\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n### How to extract data from a clicked notification:\nIn your `onNotification` method, just check the `payload` property, for all the incoming data from the push notification:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if (e.payload) {\\n  // Do what you need...\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Localytics\"\n}\n[/block]\n1. Copy the following code to a new file called PushAppsPushReceiver.java and add it to your project (don't forget to change the package name as needed):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package mobi.pushapps.demo.localytics;\\n\\nimport com.localytics.android.PushReceiver;\\nimport com.localytics.android.Localytics;\\n\\nimport android.content.Context;\\nimport android.content.Intent;\\nimport android.os.Bundle;\\nimport mobi.pushapps.PABuildNotificationListener;\\nimport mobi.pushapps.PushApps;\\nimport mobi.pushapps.models.PANotification;\\nimport mobi.pushapps.utils.PADeviceUtils;\\n\\npublic class PushAppsPushReceiver extends PushReceiver {\\n\\n\\t@Override\\n\\tpublic void onReceive(Context context, Intent intent) {\\n\\t\\tif (intent.getAction().equals(\\\"com.google.android.c2dm.intent.REGISTRATION\\\")) {\\n\\t\\t\\tPushAppsPushReceiver.super.onReceive(context, intent);\\n\\t\\t\\treturn;\\n\\t\\t}\\n\\t\\tBundle extras = intent.getExtras();\\n\\n\\t\\tString message = \\\"\\\";\\n\\t\\tif (extras.containsKey(\\\"message\\\")) {\\n\\t\\t\\tmessage = extras.getString(\\\"message\\\");\\n\\t\\t} else {\\n\\t\\t\\tPushAppsPushReceiver.super.onReceive(context, intent);\\n\\t\\t\\treturn;\\n\\t\\t}\\n\\t\\tString campaignId = null;\\n\\t\\tString image = null;\\n\\t\\tString url = null;\\n\\n\\t\\tif (extras != null) {\\n\\t\\t\\tif (extras.containsKey(\\\"pa_c\\\")) {\\n\\t\\t\\t\\tcampaignId = extras.getString(\\\"pa_c\\\");\\n\\t\\t\\t}\\n\\t\\t\\tif (extras.containsKey(\\\"pa_i\\\")) {\\n\\t\\t\\t\\timage = extras.getString(\\\"pa_i\\\");\\n\\t\\t\\t}\\n\\t\\t\\tif (extras.containsKey(\\\"pa_u\\\")) {\\n\\t\\t\\t\\turl = extras.getString(\\\"pa_u\\\");\\n\\t\\t\\t}\\n\\t\\t}\\n\\n\\t\\tString notificationMessage = message;\\n\\t\\tString notificationTitle = PADeviceUtils.getApplicationName(context);\\n\\t\\tString notificationImage = image;\\n\\t\\tString notificationSound = null;\\n\\t\\tString notificationUrl = url;\\n    \\n    final Intent fallbackIntent = intent;\\n\\n\\t\\tPANotification notification = new PANotification.Builder().campaignId(campaignId).text(notificationMessage)\\n\\t\\t\\t\\t.sound(notificationSound).title(notificationTitle).url(notificationUrl).imageUrl(notificationImage)\\n\\t\\t\\t\\t.build();\\n\\t\\tPushApps.buildNotification(context, extras, notification, new PANotificationListener() {\\n\\n\\t\\t\\t@Override\\npublic void onMessageReceived(Context context, Bundle bundle) {\\n\\t\\t\\t\\tPushAppsPushReceiver.super.onReceive(context, fallbackIntent);\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t});\\n\\t\\t\\n\\t\\tLocalytics.handlePushNotificationReceived(intent);\\n\\t}\\n\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. In your AndroidManifest.xml replace the following lines:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver\\n    android:name=\\\"com.localytics.android.PushReceiver\\\"\\n    android:permission=\\\"com.google.android.c2dm.permission.SEND\\\" >\\n    <intent-filter>\\n        <action android:name=\\\"com.google.android.c2dm.intent.REGISTRATION\\\" />\\n        <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />            \\n        <category android:name=\\\"YOUR-PACKAGE-NAME\\\" />\\n    </intent-filter>\\n</receiver>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nwith those (don't forget to replace `PACKAGE-NAME-FOR-THIS-FILE` and `YOUR-PACKAGE-NAME` with the correct values):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver\\n    android:name=\\\"PACKAGE-NAME-FOR-THIS-FILE.PushAppsPushReceiver\\\"\\n    android:permission=\\\"com.google.android.c2dm.permission.SEND\\\" >\\n    <intent-filter>\\n        <action android:name=\\\"com.google.android.c2dm.intent.REGISTRATION\\\" />\\n        <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />            \\n        <category android:name=\\\"YOUR-PACKAGE-NAME\\\" />\\n    </intent-filter>\\n</receiver>\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n3. In the PushAppsPushReceiver.java file, you can modify the parameters pass to the PushApps SDK, according to your push notification payload.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Parse\"\n}\n[/block]\n1. Copy the following code to a new file called PushAppsParseReceiver.java and add it to your project (don't forget to change the package name as needed):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package mobi.pushapps.demo.parse;\\n\\nimport org.json.JSONException;\\nimport org.json.JSONObject;\\n\\nimport com.parse.ParsePushBroadcastReceiver;\\n\\nimport android.content.Context;\\nimport android.content.Intent;\\nimport mobi.pushapps.PABuildNotificationListener;\\nimport mobi.pushapps.PushApps;\\nimport mobi.pushapps.models.PANotification;\\n\\npublic class PushAppsParseReceiver extends ParsePushBroadcastReceiver {\\n\\t\\n\\tpublic static final String PARSE_DATA_KEY = \\\"com.parse.Data\\\";\\n\\t\\n    @Override\\n    protected void onPushReceive(Context context, Intent intent) {\\n        try {\\n            JSONObject data = getDataFromIntent(intent);\\n            if (data == null) return;\\n            String campaignId = \\\"\\\";\\n            if (data.has(\\\"pa_c\\\")) {\\n                campaignId = data.getString(\\\"pa_c\\\");\\n            }\\n            String text = \\\"\\\";\\n            if (data.has(\\\"text\\\")) {\\n                text = data.getString(\\\"text\\\");\\n            }\\n            String url = \\\"\\\";\\n            if (data.has(\\\"pa_u\\\")) {\\n                url = data.getString(\\\"pa_u\\\");\\n            }\\n            String image = \\\"\\\";\\n            if (data.has(\\\"pa_i\\\")) {\\n                image = data.getString(\\\"pa_i\\\");\\n            }\\n          \\n            final Intent fallbackIntent = intent;\\n          \\n            PANotification notification = new PANotification.Builder()\\n                    .campaignId(campaignId)\\n                    .text(text)\\n                            //.sound(NOTIFICATION_SOUND) // optional\\n                            //.title(NOTIFICATION_TITLE) // optional\\n                    .url(url)\\n                    .imageUrl(image)\\n                    .build();\\n            PushApps.buildNotification(context, intent.getExtras(), notification, new PANotificationListener() {\\n                @Override\\n                public void onMessageReceived(Context context, Bundle bundle) {\\n                \\tPushAppsParseReceiver.super.onPushReceive(context, fallbackIntent);\\n                }\\n            });\\n        } catch (Exception e) {\\n            e.printStackTrace();\\n        }\\n    }\\n\\n    @Override\\n    protected void onPushDismiss(Context context, Intent intent) {\\n        super.onPushDismiss(context, intent);\\n    }\\n\\n    @Override\\n    protected void onPushOpen(Context context, Intent intent) {\\n        super.onPushOpen(context, intent);\\n    }\\n\\n    private JSONObject getDataFromIntent(Intent intent) {\\n        JSONObject data = null;\\n        try {\\n            data = new JSONObject(intent.getExtras().getString(PARSE_DATA_KEY));\\n        } catch (JSONException e) {\\n        }\\n        return data;\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. In your AndroidManifest.xml replace the following lines:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver android:name=\\\".ParsePushBroadcastReceiver\\\"\\n            android:exported=\\\"false\\\">\\n            <intent-filter>\\n                <action android:name=\\\"com.parse.push.intent.RECEIVE\\\" />\\n                <action android:name=\\\"com.parse.push.intent.DELETE\\\" />\\n                <action android:name=\\\"com.parse.push.intent.OPEN\\\" />\\n            </intent-filter>\\n        </receiver>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nwith those lines:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver android:name=\\\"mobi.pushapps.demo.parse.PushAppsParseReceiver\\\"\\n            android:exported=\\\"false\\\">\\n            <intent-filter>\\n                <action android:name=\\\"com.parse.push.intent.RECEIVE\\\" />\\n                <action android:name=\\\"com.parse.push.intent.DELETE\\\" />\\n                <action android:name=\\\"com.parse.push.intent.OPEN\\\" />\\n            </intent-filter>\\n        </receiver>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Can't find your push provider here?\",\n  \"body\": \"Please let us know and we will try to assist with integrating PushApps with your push provider.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Adobe Phonegap Plugin\"\n}\n[/block]\n1. If you already installed the Adobe plugin before, please remove it by running the following command:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cordova plugin rm phonegap-plugin-push\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n2. Install the plugin, which is already integrated with the PushApps SDK, by running the following command (don't forget to replace the variables values with yours):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cordova plugin add https://github.com/PushAppsPlatform/phonegap-plugin-push.git --variable SENDER_ID=\\\"<YOUR_SENDER_ID>\\\" --variable PA_SDK_KEY=\\\"<YOUR_PUSHAPPS_SDK_KEY>\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n3. Check out the following example, in order to register a device to receive enriched push notifications (replace <YOUR_SENDER_ID> with your value):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var push = PushNotification.init({\\n    android: {\\n        senderID: \\\"<YOUR_SENDER_ID>\\\"\\n    },\\n    ios: {\\n        alert: \\\"true\\\",\\n        badge: \\\"true\\\",\\n        sound: \\\"true\\\"\\n    },\\n    windows: {}\\n});\\n\\npush.on('registration', function(data) {\\n        alert(data.registrationId);\\n    // data.registrationId\\n});\\n\\npush.on('notification', function(data) {\\n        alert(JSON.stringify(data.additionalData));\\n    // if you are using PushApps content recommendations feature, you can get the clicked article by - data.additionalData.PAArticleUrl\\n});\\n\\npush.on('error', function(e) {\\n    alert(e.message);\\n        // e.message\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Mixpanel\"\n}\n[/block]\n1. Remove Mixpanel receiver from the AndroidManifest. Search for `com.mixpanel.android.mpmetrics.GCMReceiver`.\n\n2. In your application file, after calling the `PushApps.register(this)` method, paste the following code: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setNotificationListener(this, new PANotificationListener() {\\n\\t\\t\\t\\n\\t\\t\\t@Override\\n\\t\\t\\tpublic void onMessageReceived(Context context, Bundle bundle) {\\n        \\tif (bundle.containsKey(\\\"mp_message\\\")) {\\n        \\t\\t\\tString text = bundle.getString(\\\"mp_message\\\");\\n        \\t\\t\\tString campaignId = \\\"\\\";\\n            \\tif (bundle.containsKey(\\\"pa_c\\\")) {\\n                \\tcampaignId = bundle.getString(\\\"pa_c\\\");\\n              }\\n            \\tString url = \\\"\\\";\\n              if (bundle.containsKey(\\\"pa_u\\\")) {\\n                \\turl = bundle.getString(\\\"pa_u\\\");\\n              }\\n            \\tString image = \\\"\\\";\\n              if (bundle.containsKey(\\\"pa_i\\\")) {\\n                \\timage = bundle.getString(\\\"pa_i\\\");\\n            \\t}\\n            \\tPANotification notification = new PANotification.Builder()\\n                    .campaignId(campaignId)\\n                    .text(text)\\n                            //.sound(NOTIFICATION_SOUND) // optional\\n                            //.title(NOTIFICATION_TITLE) // optional\\n                    .url(url)\\n                    .imageUrl(image)\\n                    .build();\\n            \\tPushApps.buildNotification(context, bundle, notification, null);\\n    \\t\\t\\t}\\n\\t\\t\\t}\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"OneSignal\"\n}\n[/block]\n1. In your `AndroidManifest.xml` file, add ( or replace if existing ) the following service:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<service         \\t       \\n  android:name=\\\"mobi.pushapps.external.PAOneSignalNotificationExtenderBareBones\\\"\\n  android:exported=\\\"false\\\">\\n  <intent-filter>\\n    <action android:name=\\\"com.onesignal.NotificationExtender\\\" />\\n  </intent-filter>\\n</service>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n2. In your `Application` file, add the following code, right after registering the device to PushApps:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setNotificationListener(this, new PANotificationListener() {\\n\\n\\t\\t\\t@Override\\n\\t\\t\\tpublic void onMessageReceived(Context context, Bundle bundle) {\\n\\t\\t\\t\\tString text = \\\"\\\";\\n\\t\\t\\t\\tString title = \\\"\\\";\\n\\t\\t\\t\\tString paCampaignId = \\\"\\\";\\n\\t\\t        String paUrl = \\\"\\\";\\n\\t\\t        String paImageUrl = \\\"\\\";\\n\\n\\t\\t        try {\\n\\t\\t        \\tif (bundle.containsKey(\\\"alert\\\")) {\\n\\t\\t        \\t\\ttext = bundle.getString(\\\"alert\\\");\\n\\t\\t        \\t}\\n\\t\\t        \\tif (bundle.containsKey(\\\"title\\\")) {\\n\\t\\t        \\t\\ttitle = bundle.getString(\\\"title\\\");\\n\\t\\t        \\t}\\n              //get large image\\n              if (bundle.containsKey(\\\"bicon\\\")) {\\n                paImageUrl = bundle.getString(\\\"bicon\\\");\\n              }\\n\\t\\t        \\t\\n\\t\\t        \\tif (bundle.containsKey(\\\"custom\\\")) {\\n\\t\\t        \\t\\t\\n\\t\\t        \\t\\tJSONObject jsonObject = new JSONObject(bundle.getString(\\\"custom\\\"));\\n\\t\\t        \\t\\tif (jsonObject.has(\\\"a\\\")) {\\n\\t\\t        \\t\\t\\t\\n\\t\\t        \\t\\t\\tJSONObject innerJsonObject = jsonObject.getJSONObject(\\\"a\\\");\\n\\t\\t        \\t\\t\\tif (innerJsonObject.has(\\\"pa_c\\\")) {\\n\\t\\t\\t        \\t\\t\\tpaCampaignId = innerJsonObject.getString(\\\"pa_c\\\");\\n\\t\\t\\t        \\t\\t}\\n\\t\\t\\t        \\t\\tif (innerJsonObject.has(\\\"pa_u\\\")) {\\n\\t\\t\\t        \\t\\t\\tpaUrl = innerJsonObject.getString(\\\"pa_u\\\");\\n\\t\\t\\t        \\t\\t}\\n\\t\\t\\t        \\t\\tif (innerJsonObject.has(\\\"pa_i\\\")) {\\n\\t\\t\\t        \\t\\t\\tpaImageUrl = innerJsonObject.getString(\\\"pa_i\\\");\\n\\t\\t\\t        \\t\\t}\\n\\t\\t        \\t\\t\\t\\n\\t\\t        \\t\\t}\\n\\t\\t        \\t\\t\\n\\t\\t        \\t}\\n\\n\\t\\t        } catch (Exception e) {}\\n\\n\\t\\t        PANotification notification = new PANotification.Builder()\\n\\t\\t                .text(text)\\n\\t\\t                .campaignId(paCampaignId)\\n\\t\\t                .title(title)\\n\\t\\t                .url(paUrl)\\n\\t\\t                .imageUrl(paImageUrl)\\n\\t\\t                .build();\\n\\t\\t        PushApps.buildNotification(getApplicationContext(), bundle, notification, null);\\n\\t\\t\\t}\\n\\t\\t});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"PushBots\"\n}\n[/block]\n1. Remove from your AndroidManifest.xml the following line from the PushBots code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n2. In your Application file, add the following code, right after the registration to PushApps:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setNotificationListener(this, new PANotificationListener() {\\n\\n            @Override\\n            public void onMessageReceived(Context context, Bundle bundle) {\\n\\n                Bundle extras = bundle;\\n\\n                String campaignId = null;\\n                String image = null;\\n                String url = null;\\n\\n                if (extras != null) {\\n                    if (extras.containsKey(\\\"pa_c\\\")) {\\n                        campaignId = extras.getString(\\\"pa_c\\\");\\n                    }\\n                    if (extras.containsKey(\\\"pa_i\\\")) {\\n                        image = extras.getString(\\\"pa_i\\\");\\n                    }\\n                    if (extras.containsKey(\\\"pa_u\\\")) {\\n                        url = extras.getString(\\\"pa_u\\\");\\n                    }\\n                }\\n\\n                String notificationMessage = extras.getString(\\\"message\\\");\\n                String notificationTitle = \\\"\\\";\\n                String notificationImage = image;\\n                String notificationSound = extras.getString(\\\"sound\\\");\\n                String notificationUrl = url;\\n\\n                PANotification notification = new PANotification.Builder()\\n                        .campaignId(campaignId)\\n                        .text(notificationMessage)\\n                        .sound(notificationSound)\\n                        .title(notificationTitle)\\n                        .url(notificationUrl)\\n                        .imageUrl(notificationImage)\\n                        .build();\\n                PushApps.buildNotification(getApplicationContext(), extras, notification, new PANotificationListener() {\\n                    @Override\\n                    public void onMessageReceived(Context context, Bundle bundle) {\\n\\n                    }\\n                });\\n\\n            }\\n        });\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n3. Use the custom payload features, in order to send the extra parameters:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/42fcbc4-Screen_Shot_2016-08-19_at_1.09.28_PM.png\",\n        \"Screen Shot 2016-08-19 at 1.09.28 PM.png\",\n        891,\n        303,\n        \"#dfe3e2\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Swrve\"\n}\n[/block]\n1. Create a new class called `PushAppsGcmReceiver` with the following code (you can place wherever you want in your project):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import android.content.Context;\\nimport android.content.Intent;\\nimport android.os.Bundle;\\n\\nimport com.swrve.sdk.gcm.SwrveGcmIntentService;\\n\\npublic class PushAppsGcmReceiver extends SwrveGcmIntentService {\\n    @Override\\n    public void onReceive(Context context, Intent intent) {\\n        boolean interceptedIntent = false;\\n        if(\\\"com.google.android.c2dm.intent.RECEIVE\\\".equals(intent.getAction())) {\\n            Bundle extras = intent.getExtras();\\n            if (extras != null) {\\n                String paCampaignId = extras.get(\\\"pa_c\\\");\\n                if (paCampaignId != null && paCampaignId.lentgh() > 0) {\\n                    PANotification notification = new PANotification.Builder()\\n                        .campaignId(paCampaignId)\\n                        .text(\\\"Your text\\\")\\n                        .sound(\\\"Your sound (optional)\\\")\\n                        .title(\\\"Your title (optional)\\\")\\n                        .url(\\\"Your url (optional)\\\")\\n                        .imageUrl(\\\"Your image url (optional)\\\")\\n                        .build();\\n                PushApps.buildNotification(getApplicationContext(), extras, notification, new PANotificationListener() {\\n                    @Override\\n                    public void onMessageReceived(Context context, Bundle bundle) {\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t// Can't build enriched notification\\n                      \\tsuper.onReceive(context, intent);\\n                    }\\n                });\\n                }\\n              \\telse {\\n                  \\t// No PA cmapaign id, go by defualt\\n                  \\tsuper.onReceive(context, intent);\\n                }\\n            }\\n        }\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. In your manifest, replace the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<service android:name=\\\"com.swrve.sdk.gcm.SwrveGcmIntentService\\\" >\\n            <intent-filter>\\n                <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />\\n            </intent-filter>\\n        </service>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nwith that one:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<service android:name=\\\"<your-package-name>.PushAppsGcmReceiver\\\" >\\n            <intent-filter>\\n                <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />\\n            </intent-filter>\\n        </service>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Custom Push Provider\"\n}\n[/block]\nTo support enriched notification through your own custom push provider, add the following code to your message received service, instead of your code, that responsible on showing the notification:\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Bundle Keys\",\n  \"body\": \"Don't forget to change the bundle keys (e.g. \\\"text\\\", \\\"title\\\" etc.) to your own custom keys.\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n@Override\\npublic void onMessageReceived(Context context, Bundle bundle) {\\n\\t\\tString text = \\\"\\\";\\n\\t\\tString title = \\\"\\\";\\n\\t\\tString paCampaignId = \\\"\\\";\\n\\t\\tString paUrl = \\\"\\\";\\n\\t\\tString paImageUrl = \\\"\\\";\\n\\n\\t\\ttry {\\n\\t\\t     if (bundle.containsKey(\\\"text\\\")) {\\n\\t\\t        text = bundle.getString(\\\"text\\\");\\n\\t\\t     }\\n\\t\\t     if (bundle.containsKey(\\\"title\\\")) {\\n\\t\\t        title = bundle.getString(\\\"title\\\");\\n\\t\\t     }\\n         if (bundle.containsKey(\\\"image_url\\\")) {\\n            paImageUrl = bundle.getString(\\\"image_url\\\");\\n         }\\n\\t\\t     if (bundle.containsKey(\\\"pa_c\\\")) {\\n\\t\\t\\t      paCampaignId = bundle.getString(\\\"pa_c\\\");\\n\\t\\t\\t   }\\n\\t\\t\\t   if (bundle.containsKey(\\\"pa_u\\\")) {\\n\\t\\t\\t      paUrl = bundle.getString(\\\"pa_u\\\");\\n\\t\\t\\t   }\\n\\n\\t\\t    PANotification notification = new PANotification.Builder()\\n\\t\\t                .text(text)\\n\\t\\t                .campaignId(paCampaignId)\\n\\t\\t                .title(title)\\n\\t\\t                .url(paUrl)\\n\\t\\t                .imageUrl(paImageUrl)\\n\\t\\t                .build();\\n\\t\\t    PushApps.buildNotification(getApplicationContext(), bundle, notification, null);\\n\\t\\t\\t}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"integration-with-external-push-providers","type":"basic","title":"External Push Providers"}

External Push Providers


The following instructions will help you integrate the PushApps SDK, with your current external push provider. Please choose your one: * [Urabn Airship](#urban-airship) * [PushWoosh](#pushwoosh) * [Azure](#azure) * [Phonegap plugin (com.phonegap.plugins.PushPlugin)](#phonegap-plugin) * [Localytics](#localytics) * [Parse](#parse) * [Adobe Phonegap Plugin](#adobe-phonegap-plugin) * [Mixpanel](#mixpanel) * [OneSignal](#onesignal) * [PushBots](#pushbots) * [Swrve](#swrve) * [Custom Push Provider](#custom-push-provider) [block:api-header] { "type": "basic", "title": "Urban Airship" } [/block] 1. Copy the following code to a new file called PushAppsCustomNotificationFactory.java and add it to your project (don't forget to change the package name as needed): [block:code] { "codes": [ { "code": "package mobi.pushapps.demo.urbanairship;\n\nimport android.app.Notification;\nimport android.content.Context;\nimport android.content.Intent;\n\nimport com.urbanairship.push.PushMessage;\nimport com.urbanairship.push.notifications.NotificationFactory;\nimport com.urbanairship.util.NotificationIdGenerator;\n\nimport mobi.pushapps.PABuildNotificationListener;\nimport mobi.pushapps.PushApps;\nimport mobi.pushapps.models.PANotification;\nimport mobi.pushapps.utils.PALogger;\n\n/**\n * Created by Asaf Ron on 31/03/16.\n */\npublic class PushAppsCustomNotificationFactory extends NotificationFactory {\n\n public PushAppsCustomNotificationFactory(Context context) {\n super(context);\n }\n\n @Override\n public Notification createNotification(PushMessage message, int notificationId) {\n String paCampaignId = \"\";\n String paUrl = \"\";\n String paImageUrl = \"\";\n\n try {\n paCampaignId = message.getPushBundle().getString(\"pa_c\");\n } catch (Exception e) {\n PALogger.logError(\"Could not get pa campaign id: \" + e.getLocalizedMessage());\n }\n\n try {\n paUrl = message.getPushBundle().getString(\"pa_u\");\n } catch (Exception e) {\n PALogger.logError(\"Could not get pa url: \" + e.getLocalizedMessage());\n }\n\n try {\n paImageUrl = message.getPushBundle().getString(\"pa_i\");\n } catch (Exception e) {\n PALogger.logError(\"Could not get pa image url: \" + e.getLocalizedMessage());\n }\n\n PANotification notification = new PANotification.Builder()\n .text(message.getAlert())\n .campaignId(paCampaignId) // optional, replace with campaign id\n .title(message.getTitle()) // optional, replace with a custom title\n .url(paUrl) // optinal, replace with main url of the notification\n .imageUrl(paImageUrl) // optinal, replace with main image url\n .build();\n PushApps.buildNotification(this.getContext(), message.getPushBundle(), notification, new\n PANotificationListener() {\n @Override\n\t\t\t\t\t\tpublic void onMessageReceived(Context context, Bundle bundle) {\n PALogger.logError(\"Could not show enriched notification\");\n }\n });\n\n return null;\n }\n\n @Override\n public int getNextId(PushMessage pushMessage) {\n return NotificationIdGenerator.nextID();\n }\n\n}", "language": "java" } ] } [/block] 3. In your application class, after registering to Urban Airship, paste the following code: [block:code] { "codes": [ { "code": "UAirship.shared().getPushManager().setNotificationFactory(new PushAppsCustomNotificationFactory(this));", "language": "java" } ] } [/block] 4. Continue to Step 5 in the [Android SDK Installation (Android Studio / Eclipse)](doc:sdk-installation-eclipse) [block:api-header] { "type": "basic", "title": "PushWoosh" } [/block] ### Native SDK 1. If you implemented PushWoosh through gradle, please add the following code inside `OnCreate` method inside your `Appliction` class: [block:code] { "codes": [ { "code": "@Override\n public void onCreate() {\n super.onCreate();\n\n PushApps.register(this); // Register device to PushApps\n PushApps.setNotificationListener(this, new PANotificationListener() {\n\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n Bundle extras = bundle;\n\n String campaignId = null;\n String image = null;\n String url = null;\n\n if (extras != null) {\n url = extras.getString(\"l\");\n if (url != null) {\n extras.remove(\"l\");\n extras.putString(\"ll\", url);\n }\n if (extras.containsKey(\"pa_c\")) {\n campaignId = extras.getString(\"pa_c\");\n }\n if (extras.containsKey(\"pa_i\")) {\n image = extras.getString(\"pa_i\");\n }\n if (extras.containsKey(\"pa_u\")) {\n url = extras.getString(\"pa_u\");\n }\n }\n\n String notificationMessage = extras.getString(\"title\");\n String notificationTitle = extras.getString(\"header\") != null ? extras.getString(\"header\") : PADeviceUtils.getApplicationName(getApplicationContext());\n String notificationImage = image;\n String notificationSound = extras.getString(\"s\");\n String notificationUrl = url;\n\n PANotification notification = new PANotification.Builder()\n .campaignId(campaignId)\n .text(notificationMessage)\n .sound(notificationSound)\n .title(notificationTitle)\n .url(notificationUrl)\n .imageUrl(notificationImage)\n .build();\n PushApps.buildNotification(getApplicationContext(), extras, notification, null);\n\n }\n });\n }", "language": "java" } ] } [/block] 2. Continue to Step 5 in the [Android SDK Installation (Android Studio / Eclipse)](doc:sdk-installation-eclipse) ### Phonegap plugin 1. Please make sure you have the latest PushWoosh Cordova plugin. If you're not sure, you can execute the following commands in your terminal: [block:code] { "codes": [ { "code": "$ cordova plugin rm pushwoosh-cordova-plugin\n$ cordova plugin add pushwoosh-cordova-plugin", "language": "shell" } ] } [/block] 2. Add PushApps plugin by executing the following command (Replace YOUR--PUSHAPPS--SDK--KEY with your PushApps SDK Key): [block:code] { "codes": [ { "code": "$ cordova plugin add https://github.com/PushAppsPlatform/pushwoosh-cordova-pushapps-plugin-rtl.git --variable PA_SDK_KEY=YOUR--PUSHAPPS--SDK--KEY", "language": "shell" } ] } [/block] *Handle user clicks on notifications:* In your `push-notification` event listener method, the clicked recommendation URL will appear in: [block:code] { "codes": [ { "code": "var pushappsArticle = event.notification.PAArticleUrl;\nif (pushappsArticle) {\n\t\t// Go to the PushApps Clicked content\n} else {\n\t\t// Do what you’re doing today, open your main notification content\n}", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Azure" } [/block] 1. In your class that extends `com.microsoft.windowsazure.notifications.NotificationsHandler`, please add the following lines, inside the `onReceive` method, instead of executing your original notification building code flow: [block:code] { "codes": [ { "code": "PANotification notification = new PANotification.Builder()\n .text(NOTIFICATION_MESSAGE)\n .campaignId(THE_CAMPAIGN_ID) // optional, replace with campaign id \n .sound(NOTIFICATION_SOUND) // optional, replace with your sound file name\n .title(NOTIFICATION_TITLE) // optional, replace with a custom title\n .url(NOTIFICATION_URI) // optinal, replace with main url of the notification\n .imageUrl(NOTIFICATION_IMAGE_URL) // optinal, replace with main image url\n .build();\nPushApps.buildNotification(context, bundle, notification, new \t \n PANotificationListener() {\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n // This block code will be executed if no \n // enrichment can be shown at the moment. \n // Please execute your “old” push notification \n // code here.\n }\n});", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Phonegap Plugin (com.phonegap.plugins.PushPlugin)" } [/block] 1. Remove your current plugin installation: [block:code] { "codes": [ { "code": "$ cordova plugin rm com.phonegap.plugins.PushPlugin", "language": "shell" } ] } [/block] 2. Add the updated plugin to your application (Replace YOUR--PUSHAPPS--SDK--KEY with your PushApps SDK Key): [block:code] { "codes": [ { "code": "$ cordova plugin add https://github.com/asafron/PushPlugin.git --variable PA_SDK_KEY=<YOUR_PUSHAPPS_SDK_KEY>", "language": "shell" } ] } [/block] ### How to extract data from a clicked notification: In your `onNotification` method, just check the `payload` property, for all the incoming data from the push notification: [block:code] { "codes": [ { "code": "if (e.payload) {\n // Do what you need...\n}", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Localytics" } [/block] 1. Copy the following code to a new file called PushAppsPushReceiver.java and add it to your project (don't forget to change the package name as needed): [block:code] { "codes": [ { "code": "package mobi.pushapps.demo.localytics;\n\nimport com.localytics.android.PushReceiver;\nimport com.localytics.android.Localytics;\n\nimport android.content.Context;\nimport android.content.Intent;\nimport android.os.Bundle;\nimport mobi.pushapps.PABuildNotificationListener;\nimport mobi.pushapps.PushApps;\nimport mobi.pushapps.models.PANotification;\nimport mobi.pushapps.utils.PADeviceUtils;\n\npublic class PushAppsPushReceiver extends PushReceiver {\n\n\t@Override\n\tpublic void onReceive(Context context, Intent intent) {\n\t\tif (intent.getAction().equals(\"com.google.android.c2dm.intent.REGISTRATION\")) {\n\t\t\tPushAppsPushReceiver.super.onReceive(context, intent);\n\t\t\treturn;\n\t\t}\n\t\tBundle extras = intent.getExtras();\n\n\t\tString message = \"\";\n\t\tif (extras.containsKey(\"message\")) {\n\t\t\tmessage = extras.getString(\"message\");\n\t\t} else {\n\t\t\tPushAppsPushReceiver.super.onReceive(context, intent);\n\t\t\treturn;\n\t\t}\n\t\tString campaignId = null;\n\t\tString image = null;\n\t\tString url = null;\n\n\t\tif (extras != null) {\n\t\t\tif (extras.containsKey(\"pa_c\")) {\n\t\t\t\tcampaignId = extras.getString(\"pa_c\");\n\t\t\t}\n\t\t\tif (extras.containsKey(\"pa_i\")) {\n\t\t\t\timage = extras.getString(\"pa_i\");\n\t\t\t}\n\t\t\tif (extras.containsKey(\"pa_u\")) {\n\t\t\t\turl = extras.getString(\"pa_u\");\n\t\t\t}\n\t\t}\n\n\t\tString notificationMessage = message;\n\t\tString notificationTitle = PADeviceUtils.getApplicationName(context);\n\t\tString notificationImage = image;\n\t\tString notificationSound = null;\n\t\tString notificationUrl = url;\n \n final Intent fallbackIntent = intent;\n\n\t\tPANotification notification = new PANotification.Builder().campaignId(campaignId).text(notificationMessage)\n\t\t\t\t.sound(notificationSound).title(notificationTitle).url(notificationUrl).imageUrl(notificationImage)\n\t\t\t\t.build();\n\t\tPushApps.buildNotification(context, extras, notification, new PANotificationListener() {\n\n\t\t\t@Override\npublic void onMessageReceived(Context context, Bundle bundle) {\n\t\t\t\tPushAppsPushReceiver.super.onReceive(context, fallbackIntent);\n\t\t\t\treturn;\n\t\t\t}\n\t\t});\n\t\t\n\t\tLocalytics.handlePushNotificationReceived(intent);\n\t}\n\n}", "language": "java" } ] } [/block] 2. In your AndroidManifest.xml replace the following lines: [block:code] { "codes": [ { "code": "<receiver\n android:name=\"com.localytics.android.PushReceiver\"\n android:permission=\"com.google.android.c2dm.permission.SEND\" >\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.REGISTRATION\" />\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\" /> \n <category android:name=\"YOUR-PACKAGE-NAME\" />\n </intent-filter>\n</receiver>", "language": "xml" } ] } [/block] with those (don't forget to replace `PACKAGE-NAME-FOR-THIS-FILE` and `YOUR-PACKAGE-NAME` with the correct values): [block:code] { "codes": [ { "code": "<receiver\n android:name=\"PACKAGE-NAME-FOR-THIS-FILE.PushAppsPushReceiver\"\n android:permission=\"com.google.android.c2dm.permission.SEND\" >\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.REGISTRATION\" />\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\" /> \n <category android:name=\"YOUR-PACKAGE-NAME\" />\n </intent-filter>\n</receiver>", "language": "text" } ] } [/block] 3. In the PushAppsPushReceiver.java file, you can modify the parameters pass to the PushApps SDK, according to your push notification payload. [block:api-header] { "type": "basic", "title": "Parse" } [/block] 1. Copy the following code to a new file called PushAppsParseReceiver.java and add it to your project (don't forget to change the package name as needed): [block:code] { "codes": [ { "code": "package mobi.pushapps.demo.parse;\n\nimport org.json.JSONException;\nimport org.json.JSONObject;\n\nimport com.parse.ParsePushBroadcastReceiver;\n\nimport android.content.Context;\nimport android.content.Intent;\nimport mobi.pushapps.PABuildNotificationListener;\nimport mobi.pushapps.PushApps;\nimport mobi.pushapps.models.PANotification;\n\npublic class PushAppsParseReceiver extends ParsePushBroadcastReceiver {\n\t\n\tpublic static final String PARSE_DATA_KEY = \"com.parse.Data\";\n\t\n @Override\n protected void onPushReceive(Context context, Intent intent) {\n try {\n JSONObject data = getDataFromIntent(intent);\n if (data == null) return;\n String campaignId = \"\";\n if (data.has(\"pa_c\")) {\n campaignId = data.getString(\"pa_c\");\n }\n String text = \"\";\n if (data.has(\"text\")) {\n text = data.getString(\"text\");\n }\n String url = \"\";\n if (data.has(\"pa_u\")) {\n url = data.getString(\"pa_u\");\n }\n String image = \"\";\n if (data.has(\"pa_i\")) {\n image = data.getString(\"pa_i\");\n }\n \n final Intent fallbackIntent = intent;\n \n PANotification notification = new PANotification.Builder()\n .campaignId(campaignId)\n .text(text)\n //.sound(NOTIFICATION_SOUND) // optional\n //.title(NOTIFICATION_TITLE) // optional\n .url(url)\n .imageUrl(image)\n .build();\n PushApps.buildNotification(context, intent.getExtras(), notification, new PANotificationListener() {\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n \tPushAppsParseReceiver.super.onPushReceive(context, fallbackIntent);\n }\n });\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n @Override\n protected void onPushDismiss(Context context, Intent intent) {\n super.onPushDismiss(context, intent);\n }\n\n @Override\n protected void onPushOpen(Context context, Intent intent) {\n super.onPushOpen(context, intent);\n }\n\n private JSONObject getDataFromIntent(Intent intent) {\n JSONObject data = null;\n try {\n data = new JSONObject(intent.getExtras().getString(PARSE_DATA_KEY));\n } catch (JSONException e) {\n }\n return data;\n }\n}", "language": "java" } ] } [/block] 2. In your AndroidManifest.xml replace the following lines: [block:code] { "codes": [ { "code": "<receiver android:name=\".ParsePushBroadcastReceiver\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.parse.push.intent.RECEIVE\" />\n <action android:name=\"com.parse.push.intent.DELETE\" />\n <action android:name=\"com.parse.push.intent.OPEN\" />\n </intent-filter>\n </receiver>", "language": "xml" } ] } [/block] with those lines: [block:code] { "codes": [ { "code": "<receiver android:name=\"mobi.pushapps.demo.parse.PushAppsParseReceiver\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.parse.push.intent.RECEIVE\" />\n <action android:name=\"com.parse.push.intent.DELETE\" />\n <action android:name=\"com.parse.push.intent.OPEN\" />\n </intent-filter>\n </receiver>", "language": "xml" } ] } [/block] [block:callout] { "type": "info", "title": "Can't find your push provider here?", "body": "Please let us know and we will try to assist with integrating PushApps with your push provider." } [/block] [block:api-header] { "type": "basic", "title": "Adobe Phonegap Plugin" } [/block] 1. If you already installed the Adobe plugin before, please remove it by running the following command: [block:code] { "codes": [ { "code": "cordova plugin rm phonegap-plugin-push", "language": "shell" } ] } [/block] 2. Install the plugin, which is already integrated with the PushApps SDK, by running the following command (don't forget to replace the variables values with yours): [block:code] { "codes": [ { "code": "cordova plugin add https://github.com/PushAppsPlatform/phonegap-plugin-push.git --variable SENDER_ID=\"<YOUR_SENDER_ID>\" --variable PA_SDK_KEY=\"<YOUR_PUSHAPPS_SDK_KEY>\"", "language": "shell" } ] } [/block] 3. Check out the following example, in order to register a device to receive enriched push notifications (replace <YOUR_SENDER_ID> with your value): [block:code] { "codes": [ { "code": "var push = PushNotification.init({\n android: {\n senderID: \"<YOUR_SENDER_ID>\"\n },\n ios: {\n alert: \"true\",\n badge: \"true\",\n sound: \"true\"\n },\n windows: {}\n});\n\npush.on('registration', function(data) {\n alert(data.registrationId);\n // data.registrationId\n});\n\npush.on('notification', function(data) {\n alert(JSON.stringify(data.additionalData));\n // if you are using PushApps content recommendations feature, you can get the clicked article by - data.additionalData.PAArticleUrl\n});\n\npush.on('error', function(e) {\n alert(e.message);\n // e.message\n});", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Mixpanel" } [/block] 1. Remove Mixpanel receiver from the AndroidManifest. Search for `com.mixpanel.android.mpmetrics.GCMReceiver`. 2. In your application file, after calling the `PushApps.register(this)` method, paste the following code: [block:code] { "codes": [ { "code": "PushApps.setNotificationListener(this, new PANotificationListener() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void onMessageReceived(Context context, Bundle bundle) {\n \tif (bundle.containsKey(\"mp_message\")) {\n \t\t\tString text = bundle.getString(\"mp_message\");\n \t\t\tString campaignId = \"\";\n \tif (bundle.containsKey(\"pa_c\")) {\n \tcampaignId = bundle.getString(\"pa_c\");\n }\n \tString url = \"\";\n if (bundle.containsKey(\"pa_u\")) {\n \turl = bundle.getString(\"pa_u\");\n }\n \tString image = \"\";\n if (bundle.containsKey(\"pa_i\")) {\n \timage = bundle.getString(\"pa_i\");\n \t}\n \tPANotification notification = new PANotification.Builder()\n .campaignId(campaignId)\n .text(text)\n //.sound(NOTIFICATION_SOUND) // optional\n //.title(NOTIFICATION_TITLE) // optional\n .url(url)\n .imageUrl(image)\n .build();\n \tPushApps.buildNotification(context, bundle, notification, null);\n \t\t\t}\n\t\t\t}\n});", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "OneSignal" } [/block] 1. In your `AndroidManifest.xml` file, add ( or replace if existing ) the following service: [block:code] { "codes": [ { "code": "<service \t \n android:name=\"mobi.pushapps.external.PAOneSignalNotificationExtenderBareBones\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.onesignal.NotificationExtender\" />\n </intent-filter>\n</service>", "language": "xml" } ] } [/block] 2. In your `Application` file, add the following code, right after registering the device to PushApps: [block:code] { "codes": [ { "code": "PushApps.setNotificationListener(this, new PANotificationListener() {\n\n\t\t\t@Override\n\t\t\tpublic void onMessageReceived(Context context, Bundle bundle) {\n\t\t\t\tString text = \"\";\n\t\t\t\tString title = \"\";\n\t\t\t\tString paCampaignId = \"\";\n\t\t String paUrl = \"\";\n\t\t String paImageUrl = \"\";\n\n\t\t try {\n\t\t \tif (bundle.containsKey(\"alert\")) {\n\t\t \t\ttext = bundle.getString(\"alert\");\n\t\t \t}\n\t\t \tif (bundle.containsKey(\"title\")) {\n\t\t \t\ttitle = bundle.getString(\"title\");\n\t\t \t}\n //get large image\n if (bundle.containsKey(\"bicon\")) {\n paImageUrl = bundle.getString(\"bicon\");\n }\n\t\t \t\n\t\t \tif (bundle.containsKey(\"custom\")) {\n\t\t \t\t\n\t\t \t\tJSONObject jsonObject = new JSONObject(bundle.getString(\"custom\"));\n\t\t \t\tif (jsonObject.has(\"a\")) {\n\t\t \t\t\t\n\t\t \t\t\tJSONObject innerJsonObject = jsonObject.getJSONObject(\"a\");\n\t\t \t\t\tif (innerJsonObject.has(\"pa_c\")) {\n\t\t\t \t\t\tpaCampaignId = innerJsonObject.getString(\"pa_c\");\n\t\t\t \t\t}\n\t\t\t \t\tif (innerJsonObject.has(\"pa_u\")) {\n\t\t\t \t\t\tpaUrl = innerJsonObject.getString(\"pa_u\");\n\t\t\t \t\t}\n\t\t\t \t\tif (innerJsonObject.has(\"pa_i\")) {\n\t\t\t \t\t\tpaImageUrl = innerJsonObject.getString(\"pa_i\");\n\t\t\t \t\t}\n\t\t \t\t\t\n\t\t \t\t}\n\t\t \t\t\n\t\t \t}\n\n\t\t } catch (Exception e) {}\n\n\t\t PANotification notification = new PANotification.Builder()\n\t\t .text(text)\n\t\t .campaignId(paCampaignId)\n\t\t .title(title)\n\t\t .url(paUrl)\n\t\t .imageUrl(paImageUrl)\n\t\t .build();\n\t\t PushApps.buildNotification(getApplicationContext(), bundle, notification, null);\n\t\t\t}\n\t\t});", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "PushBots" } [/block] 1. Remove from your AndroidManifest.xml the following line from the PushBots code: [block:code] { "codes": [ { "code": "<action android:name=\"com.google.android.c2dm.intent.RECEIVE\" />", "language": "xml" } ] } [/block] 2. In your Application file, add the following code, right after the registration to PushApps: [block:code] { "codes": [ { "code": "PushApps.setNotificationListener(this, new PANotificationListener() {\n\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n\n Bundle extras = bundle;\n\n String campaignId = null;\n String image = null;\n String url = null;\n\n if (extras != null) {\n if (extras.containsKey(\"pa_c\")) {\n campaignId = extras.getString(\"pa_c\");\n }\n if (extras.containsKey(\"pa_i\")) {\n image = extras.getString(\"pa_i\");\n }\n if (extras.containsKey(\"pa_u\")) {\n url = extras.getString(\"pa_u\");\n }\n }\n\n String notificationMessage = extras.getString(\"message\");\n String notificationTitle = \"\";\n String notificationImage = image;\n String notificationSound = extras.getString(\"sound\");\n String notificationUrl = url;\n\n PANotification notification = new PANotification.Builder()\n .campaignId(campaignId)\n .text(notificationMessage)\n .sound(notificationSound)\n .title(notificationTitle)\n .url(notificationUrl)\n .imageUrl(notificationImage)\n .build();\n PushApps.buildNotification(getApplicationContext(), extras, notification, new PANotificationListener() {\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n\n }\n });\n\n }\n });", "language": "java" } ] } [/block] 3. Use the custom payload features, in order to send the extra parameters: [block:image] { "images": [ { "image": [ "https://files.readme.io/42fcbc4-Screen_Shot_2016-08-19_at_1.09.28_PM.png", "Screen Shot 2016-08-19 at 1.09.28 PM.png", 891, 303, "#dfe3e2" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "Swrve" } [/block] 1. Create a new class called `PushAppsGcmReceiver` with the following code (you can place wherever you want in your project): [block:code] { "codes": [ { "code": "import android.content.Context;\nimport android.content.Intent;\nimport android.os.Bundle;\n\nimport com.swrve.sdk.gcm.SwrveGcmIntentService;\n\npublic class PushAppsGcmReceiver extends SwrveGcmIntentService {\n @Override\n public void onReceive(Context context, Intent intent) {\n boolean interceptedIntent = false;\n if(\"com.google.android.c2dm.intent.RECEIVE\".equals(intent.getAction())) {\n Bundle extras = intent.getExtras();\n if (extras != null) {\n String paCampaignId = extras.get(\"pa_c\");\n if (paCampaignId != null && paCampaignId.lentgh() > 0) {\n PANotification notification = new PANotification.Builder()\n .campaignId(paCampaignId)\n .text(\"Your text\")\n .sound(\"Your sound (optional)\")\n .title(\"Your title (optional)\")\n .url(\"Your url (optional)\")\n .imageUrl(\"Your image url (optional)\")\n .build();\n PushApps.buildNotification(getApplicationContext(), extras, notification, new PANotificationListener() {\n @Override\n public void onMessageReceived(Context context, Bundle bundle) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Can't build enriched notification\n \tsuper.onReceive(context, intent);\n }\n });\n }\n \telse {\n \t// No PA cmapaign id, go by defualt\n \tsuper.onReceive(context, intent);\n }\n }\n }\n }\n}", "language": "java" } ] } [/block] 2. In your manifest, replace the following code: [block:code] { "codes": [ { "code": "<service android:name=\"com.swrve.sdk.gcm.SwrveGcmIntentService\" >\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\" />\n </intent-filter>\n </service>", "language": "xml" } ] } [/block] with that one: [block:code] { "codes": [ { "code": "<service android:name=\"<your-package-name>.PushAppsGcmReceiver\" >\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\" />\n </intent-filter>\n </service>", "language": "xml" } ] } [/block] [block:api-header] { "type": "basic", "title": "Custom Push Provider" } [/block] To support enriched notification through your own custom push provider, add the following code to your message received service, instead of your code, that responsible on showing the notification: [block:callout] { "type": "warning", "title": "Bundle Keys", "body": "Don't forget to change the bundle keys (e.g. \"text\", \"title\" etc.) to your own custom keys." } [/block] [block:code] { "codes": [ { "code": "\n@Override\npublic void onMessageReceived(Context context, Bundle bundle) {\n\t\tString text = \"\";\n\t\tString title = \"\";\n\t\tString paCampaignId = \"\";\n\t\tString paUrl = \"\";\n\t\tString paImageUrl = \"\";\n\n\t\ttry {\n\t\t if (bundle.containsKey(\"text\")) {\n\t\t text = bundle.getString(\"text\");\n\t\t }\n\t\t if (bundle.containsKey(\"title\")) {\n\t\t title = bundle.getString(\"title\");\n\t\t }\n if (bundle.containsKey(\"image_url\")) {\n paImageUrl = bundle.getString(\"image_url\");\n }\n\t\t if (bundle.containsKey(\"pa_c\")) {\n\t\t\t paCampaignId = bundle.getString(\"pa_c\");\n\t\t\t }\n\t\t\t if (bundle.containsKey(\"pa_u\")) {\n\t\t\t paUrl = bundle.getString(\"pa_u\");\n\t\t\t }\n\n\t\t PANotification notification = new PANotification.Builder()\n\t\t .text(text)\n\t\t .campaignId(paCampaignId)\n\t\t .title(title)\n\t\t .url(paUrl)\n\t\t .imageUrl(paImageUrl)\n\t\t .build();\n\t\t PushApps.buildNotification(getApplicationContext(), bundle, notification, null);\n\t\t\t}", "language": "java" } ] } [/block]