Eclipse
SDK Setup
Eclipse ADT offers you access to a range of features that help you quickly develop Android Apps.
Before you begin
Before implementing the SDK, make sure you have the following:
-
Install the Android SDK.
-
Download the Google Play Services SDK.
SDK Contents
Once you've downloaded and unzipped the SDK, you'll find one directory and one jar file:
-
docs contains the SDK documentation as plain HTML Javadoc.
-
jar the SDK implementation in a jar file.
IDE setup guide
To use the PUSHTech™ SDK in an Android Project in Eclipse, just copy the *.jar file into the libs directory in the root of the project. Eclipse will include it automatically into the project class-path.

If the library is not automatically detected, you can add it manually: Project -> Properties -> Java Build Path -> Add JARs.
Library Dependencies
PUSHTech™ Android SDK uses some awesome / fully tested open source libraries. You can add the following libraries using your preferred method.
-
Android Suport v7: Get it!
-
Play services: Get it!
-
Gson: Get it!
-
HttpCore: Get it!
-
HttpMime: Get it!
-
Libphonenumber: Get it!
If you're using Chat SDK have to add the following dependency:
-
Ez-Vcard: Get it!
AndroidManifest.xml
First you need to add the required permissions to receive In-App Push Notifications, you need to replace your.package by your package name.
<permission android:name="your.package.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="your.package.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Only in chat SDK add the next permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_SMS" />
Add the following services, provider and receivers under the application tag:
<service android:name="your.package.ExampleGCMIntentService" /> <receiver android:name="your.package.ExampleGCMBroadcastReceiver"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="your.package" /> </intent-filter> </receiver> <provider android:name="com.pushtech.sdk.PushContentProvider" android:exported="false" android:authorities="your.package"/>
Only in chat SDK add this service and receiver in AndroidManifest.xml
<service android:name="com.pushtech.sdk.MessageService" /> <receiver android:name="com.pushtech.sdk.NetworkChangeReceiver"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver>
Get your API Key from Google
In order to configure your PUSHTech™ App for Android, you must first obtain an API key from Google. The steps are:
-
Go to the Google Developers Console.
-
Create a project.
-
Enable GCM by selecting APIs & auth and turning the Google Cloud Messaging for Android toggle to ON.
-
Select APIs & auth > Credentials.
-
Under Public API access, click 'Create new key'.
-
In the Create a new key dialog, click 'Server key'.
-
Do not specify any IP addresses in the form, and click 'Create'.
Setting up your App in PUSHTech™
Inside the PUSHTech™ Manager navigate to Apps -> New App.
-
Insert a name for your application, and choose if it will use our chat and if it is intended for production or development.
-
For the iOS setup refer to the iOS SDK documentation.
-
Insert the key for server apps obtained from Google Developers Console. and your application package name.
-
Click on 'Create App'.

App Registration
After you had setup all the extended classes the SDK needs to run on your application, you should call the snipped below at the initialization of your app, typically your first activity creation. That will register the gcmId of the application on the current device to the PUSHTech™ Marketing Platform and obtain PushtechApp object to uses all SDK functions.
First we declare some private properties we're going to use with a class extension:
String GCM_APPLICATION_ID = "00000000000"; String APP_ID = "00aaa00aa000aaaa0a000000"; String APP_SECRET = "a0aa00000a0000aa000a0aaa0a000a00"; PushtechAppBuilder pushtechAppBuilder = new PushtechAppBuilder(this); pushtechAppBuilder .setAppId(APP_ID) .setAppSecret(APP_SECRET) .setGcmSenderId(GCM_APPLICATION_ID) .build(new PushtechAppbuildAsyncCallback() { @Override public void onPushtechAppBuild(PushtechApp pushtechApp) { } @Override public void onError(PushtechError error) { } });
The onPushtechAppBuild method will be called when the setup process is completed and register in GCM service and PUSHTech™ Marketing Platform. This method return a PushtechApp that contains:
The GCM token assigned to the application on that device by Google GCM (PushtechApp.with(context).getGcmToken()).
The device Id is the id assigned to the application by the PUSHTech™ Marketing Platform (PushtechApp.with(context).getDeviceId()).
The onError method will be called only if there is an exception raised during the registration process, the Exception e will have more details about the issue.
The GCM_APPLICATION_ID is the ID given by Google in the Google Developers Console for your application.
The APP_ID is the ID given by the PUSHTech™ Marketing Platform corresponding to the application created.
The APP_SECRET is the Secret given by the PUSHTech™ Marketing Platform corresponding to the application created.
The PushSetup.Environment determines if the SDK should point to the Production or Sandbox Environment.

Optional Classes
GCMBroadcastReceiver
You need to create a BroadcastReceiver that extends GcmBroadcastReceiver. You should override the getGcmServiceClass() method, this method should return the class of the PUSHTech™ GCMPushIntentService of your application. For example your basic Receiver should be like this:
public final class ExampleGCMBroadcastReceiver extends GcmBroadcastReceiver { @Override protected Class extends GCMPushIntentService> getGcmServiceClass() { return ExampleGCMIntentService.class; } }
GCMPushIntentService
If you are going to use only the Push Notifications functionalities of the PUSHTech™ SDK, you need to create a service that extends GCMPushIntentService. If you are going to use the chat functionalities of the SDK, you will need to extend GCMEventIntentService. Since GCMEventIntentService is a subclass of GCMPushIntentService you should only extend one of them. For example your basic Service should be like this:
public final class ExampleGCMIntentService extends GCMPushIntentService { }
For override the behavior of the default notifications, you should override the following methods: When a delivery of a Campaign is received: (This method is from GCMPushIntentService)
@Override public void onCampaignDelivery(CampaignDelivery delivery) //TODO show notification of new campaign received, or whatever you want. }
When a custom Push Notification send by your Backend through PUSHTech™ is received: (This method is from GCMPushIntentService)
@Override public void onBackendDelivery(BackendDelivery delivery) //TODO do whatever you have to do. }
When another Push Notification is received: (This method is from GCMPushIntentService)
@Override public void onGenericPush(Intent intent) //TODO do whatever you have to do. }
Send Metrics
Metrics are used to send information about the user or application usage to PUSHTech™ servers. All metrics are sent through the DataCollectorManager class:
//Get instance of DatacollectorManager DataCollectorManager data = DataCollectorManager.getInstance(getActivity()); //Create a custom metric type Number data.setCustomEvent("metric", "max_air", "10.3", DataCollectorManager.ValueType.NUMBER); //Create a custom metric type String data.setCustomEvent("color", "car", "Blue", DataCollectorManager.ValueType.STRING); //Create a custom metric type Boolean data.setCustomEvent("social", "like_page", "true", DataCollectorManager.ValueType.BOOLEAN); //Create a custom metric type Date data.setCustomEvent("user", "launch_date", TimeUtils.DateToISO8061(new Date()), DataCollectorManager.ValueType.DATE); //Create Social metrics data.loginFacebook(); data.setFacebookID("207336719452056"); data.setNumberFacebookFriends(5738); data.logoutFacebook(); data.loginTwitter(); data.setTwitterID("PUSHTechCloud"); data.setNumberOfTwitterFollowers(10020323); data.logoutTwitter(); data.loginGoogle(); data.setGoogleID("+Pushtechnologies"); data.logoutGoogle(); //Generic metrics login flow data.loginGeneric(); data.logoutGeneric(); data.registerGeneric(); //Create Product model PurchaseProduct product = new PurchaseProduct(); product.setName("Iphone 6"); product.setPrice((double) 843.45); product.setProductId("273023ida3892"); product.setCurrency(Currency.getInstance("EUR")); Products products = new Products(); products.setProducts(new ArrayList()); products.getProducts().add(product); data.addProductToCart(product); product = new PurchaseProduct(); product.setName("Macbook pro 13"); product.setPrice((double) 1843.45); product.setProductId("232139a30asds3"); product.setCurrency(Currency.getInstance("EUR")); products.getProducts().add(product); //Create a removed product from the cart data.removeProductFromCart(product); //Create an added product from the cart data.addProductToCart(product); //Create purchased products metrics data.purchaseProduct(products); //Create a metric to retrieve number of products in the cart data.setNumOfProductInCart(100); //User attributes metrics data.setFirstName("Jhoe"); data.setLastName("Doe"); data.setEmail("jhoe.doe@email.es"); Phonenumber.PhoneNumber phone = new Phonenumber.PhoneNumber(); phone.setRawInput("+3486666666"); data.setPhoneNumber(phone); data.setGender(DataCollectorManager.Gender.MALE); data.setBirthdate(new Date()); data.setCity("Barcelona"); try { data.setCountry(CountryHelper.getCountryByIsoCode("ES")); } catch (NotValidCountryException e) { e.printStackTrace(); } //Create metric content view data.contentView(this.getClass().getName()); //Create metric with current location data.sendGeolocation(); //To accept received push notifications, Default is true. data.subscribePushNotifications(); //To decline received push notifications data.unsubscribePushNotifications();
Metrics send automatically every 30 seconds, but you can force to send metrics now use the next function of the DataCollectorManager class
DataCollectorManager.getInstance().sendMetrics()
Notifications with actions

Customize
The Android PUSHTech SDK provide notifications with action buttons, it shows automatically with the default App icons and text. You need to add the resources described bellow in your android project in order to use this feature. If you want to customise any icon, you have to keep the name of the actions. In order to customise the text of the actions buttons just modify the strings_actions.xml file. You can find those files in PushtechSDK.zip in resources folder.
Handle actions clicked
First create your receiver class extends NotificationReceiver.class:
public class NotificationActionsReceiver extends NotificationReceiver { @Override public void actionCUSTOM(Context ctx, PushDelivery pushDelivery, String action) { openMainActivity(ctx, pushDelivery); } @Override public void actionOK(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionCANCEL(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionEDIT(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionSEND(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionBUY(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionSAVE(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionFIND(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionLIKE(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionDISLIKE(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionLAUNCH(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionREMIND(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionDELETE(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } @Override public void actionFORBID(Context ctx, PushDelivery pushDelivery) { openMainActivity(ctx, pushDelivery); } private void openMainActivity(Context ctx, PushDelivery pushDelivery) { Intent intent = new Intent(ctx, HomeActivity.class); intent.putExtra("push_delivery_id", pushDelivery.getDeliveryId()); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(intent); } }
Finally declare your receiver in your manifest to notify when it have been clicked on any action
<receiver android:name=".NotificationActionsReceiver"> <intent-filter> <action android:name="${applicationId}.OK"/> <action android:name="${applicationId}.CANCEL"/> <action android:name="${applicationId}.EDIT"/> <action android:name="${applicationId}.SEND"/> <action android:name="${applicationId}.BUY"/> <action android:name="${applicationId}.SAVE"/> <action android:name="${applicationId}.FIND"/> <action android:name="${applicationId}.LIKE"/> <action android:name="${applicationId}.DISLIKE"/> <action android:name="${applicationId}.LAUNCH"/> <action android:name="${applicationId}.REMIND"/> <action android:name="${applicationId}.DELETE"/> <action android:name="${applicationId}.FORBID"/> </intent-filter> </receiver>
PUSHTechApp
The PUSHTechApp is a singleton class to do anything with this SDK (Push Notification or Chat). All methods and functions that you can use in this class are only available if you have registered on the PUSHTech™ Marketing Platform. To do this PUSHTechApp offers a static method to check if the device is registered (PushtechApp.isRegisterUser(context)).
The PUSHTechApp contains all subclass manager that only access by PUSHTechApp:
Common:
-
DeliveryManager: The function DataCollectorManager.getInstance(this) obtains an instance of the class DataCollectorManager which are all related functions with all metrics that sends to PUSHTech™ Manager.
-
DataCollectorManager: The function DataCollectorManager.getInstance(this) obtains an instance of the class DataCollectorManager which are all related functions with all metrics that sends to PUSHTech™ Manager. In reference sections you can find an explanation of all functions metrics to be send.
Only CHAT SDK:
-
ChatRegister: This manager use to register in chat platform with user’s information.
-
BaseManager: This manager contains all manager related with the Chat functionalities:
-
MessageManager: This Contains all methods to send any message likes text, picture, video, contact, location and custom message.
-
CommunicationManager: This contains a manager to webSocket communication.
-
UserManager: This contains all functions related with the users and contacts.
-
ChatManager: This contains all methods to create, destroy, update and find any chats.
PUSHTechChat Integration
If you want to overwrite Chat Notifications you must create an service class that extends from GCMPushIntentService and override the next methods (its the same class to received Push Notification and you should only created one).
@Override public void newChatMessage(ChatMessage message) { //TODO show notification of new chat message received, or whatever you want. } @Override public void startTyping(String userJid) { //TODO do whatever you want when user start typing you. } @Override public void stopTyping(String userJid) { //TODO do whatever you want when user stop typing you. } @Override public void onInviteAGroup(GroupChat chat) { //TODO show notification of invite group received, or whatever you want. } @Override public void onJoinGroup(GroupChat chat) { //TODO show notification of join group received, or whatever you want. } @Override public void onLeaveGroup(GroupChat chat) { //TODO show notification of leave group received, or whatever you want. }
Chat functionalities
Double Opt-in user validation
For register in Chat Platform first use the next function to send a SMS code to validate the phone number (only register with a valid phone number).
PushtechApp.with(getActivity()).getChatRegister().sendCodeRegistration(phoneNumber, userName, country, new GenericCallback() { @Override public void onSuccess() { } @Override public void onError(PushtechError error) { } });
And user two alternatives to register in chat:
-
Automatically the SDK reads SMS with this function. When the onValidateUser() executes the SDK register automatically in Chat Platform.
PushtechApp.with(this).getChatRegister().setAutomaticUserValidationCallback(new AutomaticUserValidationCallback() { @Override public void onValidateUser() { } });
Use the next function with the secret code writes for final user:
PushtechApp.with(getActivity()).getChatRegister().registerWithSecretCode(secret, new GenericCallback() { @Override public void onSuccess() { } @Override public void onError(PushtechError error) { } });
First Sync
The first time a synchronization is requested, it will create all the currently open chats the user has and download the last message received or send.
Successive Syncs
On successive syncs, the SDK will request the new chats opened and the all the messages received since the last message sync.
Push based Sync
In order to avoid frequent pulling for a real time chat communication, our SDK provides two ways of pushing that will trigger a sync. Push Notification coming from GCM and events coming from an open WebSocket.
The sync from GCM Push Notification will be used when the WebSocket is not connected and will trigger the sync automatically, so you don't need to worry about it. The Push Notification coming from GCM can be noticeably slow and are best suited to save battery when the application user is not actively using your App.
The sync from an open WebSocket can be used to achieve near real time communication and listen to "is typing" like events. You can open an close the WebSocket using the following code:
PushtechApp.with(getActivity()).getBaseManager().getCommunicationService().start(); PushtechApp.with(getActivity()).getBaseManager().getCommunicationService().stop();