Our company is now using Unity 3D for a couple of major games in development and it became clear we wanted to benefit from this amazing work done by Pushwoosh team. It requires minimum efforts on our side and delivers functionality which is essential for most of the gaming projects.

Olga Zobova

Head of Mobile Games Publishing

Alawar Entertainment

READ TESTIMONIAL

Native Android SDK

Download SDK Sample Project

Due to compatibility with Android 4 please make sure you are using at least 11 version of the Android API.

The SDK will run on older devices.

NOTE: Push notifications do not work on the Android Emulator

To integrate Pushwoosh into your Android application you need to do simple following steps:

1. Download SDK from the SDK section in the Control Panel. When you unpack the archive you can either use SDK as Pushwoosh.jar (preferred) or the source package.

2. If using jar file add it to the classpath of the project.

For Eclipse: http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

For IDEA: http://stackoverflow.com/questions/1051640/correct-way-to-add-lib-jar-to-an-intellij-idea-project

2.b If using source package just add the sources to the project.

3.a In the main activity add the following receivers:

	//Registration receiver
	BroadcastReceiver mBroadcastReceiver = new RegisterBroadcastReceiver()
	{
		@Override
		public void onRegisterActionReceive(Context context, Intent intent)
		{
			checkMessage(intent);
		}
	};
	
	//Push message receiver
	private BroadcastReceiver mReceiver = new BasePushMessageReceiver()
	{
		@Override
		protected void onMessageReceive(Intent intent)
		{
			//JSON_DATA_KEY contains JSON payload of push notification.
			showMessage("push message is " + intent.getExtras().getString(JSON_DATA_KEY));
		}
	};

	//Registration of the receivers
	public void registerReceivers()
	{
		IntentFilter intentFilter = new IntentFilter(getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");

		registerReceiver(mReceiver, intentFilter);
		
		registerReceiver(mBroadcastReceiver, new IntentFilter(getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));		
	}

	public void unregisterReceivers()
	{
		//Unregister receivers on pause
		try
		{
			unregisterReceiver(mReceiver);
		}
		catch (Exception e)
		{
			// pass.
		}
		
		try
		{
			unregisterReceiver(mBroadcastReceiver);
		}
		catch (Exception e)
		{
			//pass through
		}
	}
3.b Manage receivers registration in the onPause/onResume functions
	@Override
	public void onResume()
	{
		super.onResume();
		
		//Re-register receivers on resume
		registerReceivers();
	}

	@Override
	public void onPause()
	{
		super.onPause();

		//Unregister receivers on pause
		unregisterReceivers();
	}
3.c In the main activity initialize the PushManager and register receivers:
 @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);

       //Register receivers for push notifications
       registerReceivers();

       //Create and start push manager
       PushManager pushManager = new PushManager(this, APP_ID, SENDER_ID);
       pushManager.onStartup(this);

       checkMessage(getIntent());

       // other code
   }

Where:

APP_ID – Pushwoosh Application ID

SENDER_ID – Project Number you receive from Google GCM

(see more: http://developer.android.com/guide/google/gcm/index.html and http://developer.android.com/guide/google/gcm/gs.html)

The main activity has the following tags in the AnrdoidManifest.xml:

           <intent-filter>
               <action android:name="android.intent.action.MAIN"/>
               <category android:name="android.intent.category.LAUNCHER"/>
           </intent-filter>

4. In the main activity create the following method:

    private void checkMessage(Intent intent)
    {
        if (null != intent)
        {
            if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
            {
                showMessage("push message is " + intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT));
            }
            else if (intent.hasExtra(PushManager.REGISTER_EVENT))
            {
                showMessage("register");
            }
            else if (intent.hasExtra(PushManager.UNREGISTER_EVENT))
            {
                showMessage("unregister");
            }
            else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
            {
                showMessage("register error");
            }
            else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
            {
                showMessage("unregister error");
            }

            resetIntentValues();
        }
    }

	/**
	 * Will check main Activity intent and if it contains any PushWoosh data, will clear it
	 */
	private void resetIntentValues()
	{
		Intent mainAppIntent = getIntent();

		if (mainAppIntent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
		{
			mainAppIntent.removeExtra(PushManager.PUSH_RECEIVE_EVENT);
		}
		else if (mainAppIntent.hasExtra(PushManager.REGISTER_EVENT))
		{
			mainAppIntent.removeExtra(PushManager.REGISTER_EVENT);
		}
		else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_EVENT))
		{
			mainAppIntent.removeExtra(PushManager.UNREGISTER_EVENT);
		}
		else if (mainAppIntent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
		{
			mainAppIntent.removeExtra(PushManager.REGISTER_ERROR_EVENT);
		}
		else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
		{
			mainAppIntent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT);
		}

		setIntent(mainAppIntent);
	}

    private void showMessage(String message)
    {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }

Also call this method from onNewIntent as well.

   @Override
   protected void onNewIntent(Intent intent)
   {
       super.onNewIntent(intent);
       setIntent(intent);

       checkMessage(intent);

       setIntent(new Intent());
   }

In the AndroidManifest.xml make the following changes for this activity:

       <activity android:name="YourStartActivity"
                 android:launchMode="singleTop"
                 android:label="@string/app_name">
           <intent-filter>
               <action android:name="PACKAGE_NAME.MESSAGE"/>
               <category android:name="android.intent.category.DEFAULT"/>
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.MAIN"/>
               <category android:name="android.intent.category.LAUNCHER"/>
           </intent-filter>
       </activity>

5. Add the following changes in your AndroidManifest.xml under manifest tag. Replace PACKAGE_NAME with the package name for your application.

You can find your package name in the AndroidManifest.xml under the manifest tag in the very top of the file.
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <!--library-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <!-- GCM connects to Google Services. -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>

    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <!--
     Creates a custom permission so only this app can receive its messages.

     NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
           where PACKAGE is the application's package name.
    -->
    <permission
            android:name="PACKAGE_NAME.permission.C2D_MESSAGE"
            android:protectionLevel="signature"/>
    <uses-permission
            android:name="PACKAGE_NAME.permission.C2D_MESSAGE"/>

    <!-- This app has permission to register and receive data message. -->
    <uses-permission
            android:name="com.google.android.c2dm.permission.RECEIVE"/>

    <!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
    <!-- The targetSdkVersion is optional, but it's always a good practice
         to target higher versions. -->
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>

6. Add the following changes in your AndroidManifest.xml under application tag. Replace PACKAGE_NAME with the package name for your application.

You can find your package name in the AndroidManifest.xml under the manifest tag in the very top of the file.
        <activity android:name="com.arellomobile.android.push.PushWebview"/>

        <activity android:name="com.arellomobile.android.push.MessageActivity"/>

        <activity android:name="com.arellomobile.android.push.PushHandlerActivity"/>

        <!--
          BroadcastReceiver that will receive intents from GCM
          services and handle them to the custom IntentService.

          The com.google.android.c2dm.permission.SEND permission is necessary
          so only GCM services can send data messages for the app.
        -->
        <receiver
                android:name="com.google.android.gcm.GCMBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
                <category android:name="PACKAGE_NAME"/>
            </intent-filter>
        </receiver>

        <!--
          Application-specific subclass of PushGCMIntentService that will
          handle received messages.
        -->
        <service android:name="com.arellomobile.android.push.PushGCMIntentService"/>

If you would like to use Geo Push Notifications add the following service to your manifest file:

        <!--
          Service for sending location updates
        -->
        <service android:name="com.arellomobile.android.push.GeoLocationService"/>

That’s it!

Note: If your device is connected to the Internet via WiFi, and messages don’t get through to the device, please make sure GCM ports are not blocked by your firewall.

The device accesses the GCM servers on ports 5228-5230. If your organization has a firewall that restricts the traffic to or from the Internet, you’ll need to configure it to allow connectivity with GCM. The ports to open are: 5228, 5229, and 5230. GCM typically only uses 5228, but it sometimes uses 5229 and 5230. GCM doesn’t provide specific IPs. It changes IPs frequently.

Push Notifications SDK API:

public class PushManager
{
    //initialize Push Manager
    public PushManager(Context context, String appId, String senderId);

    //must be called after initialization
    public void onStartup(Context context);

    //starts tracking Geo Push Notifications
    public void startTrackingGeoPushes();

    //stops tracking Geo Push Notifications
    public void stopTrackingGeoPushes();

    //unregisters from push notifications
    public void unregister();

    //returns user data from push notification
    public String getCustomData();

    //allows multiple notifications in notification bar
    public void setMultiNotificationMode();

    //allows only the last notification in notification bar
    public void setSimpleNotificationMode();

    //could be SoundType.NO_SOUND, DEFAULT_MODE, ALWAYS
    public void setSoundNotificationType(SoundType soundNotificationType);

    //could be VibrateType.NO_VIBRATE, DEFAULT_MODE, ALWAYS
    public void setVibrateNotificationType(VibrateType vibrateNotificationType);

    //sets tags for the device in a worker process. Do not call on the main thread!
    public Map<String, String> sendTagsFromBG(Context context, Map<String, Object> tags) throws PushWooshException;

    //sets tags for the device. Safe to call on the main thread.
    public static void sendTagsFromUI(Context context, Map<String, Object> tags, SendPushTagsCallBack callBack)
}