In this tutorial we show how to create a push-enabled application.

 

We assume that the developer already owns an account into the ArenaDaemon web platform and

owns the knowledge for creating a new application and retrieving the correspondent appKey.

Moreover, we assume that a valid GCM Api Key and Sender ID has already been created and setup

in order to make the push service working.

 

For more information about how to create a developer account and for setup a new application,

please refer to the chapter "Create an appKey".

For more information about how to setup a GCM Api Key and Sender ID,

please refer to the chapter "Push Notifications: Setup".

 

The implementation steps to perform for building a working push enabled application are few and

very simple.

 

The first step is the initial SDK setup and involves only the AndroidManifest

More in depth the following lines have to be added:

 

 

    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

 

    <permission android:name="<your.package.name>.permission.C2D_MESSAGE"

        android:protectionLevel="signature"/>

    <uses-permission android:name="<your.package.name>.permission.C2D_MESSAGE"/>

 

    <application>

        ....

        ....

        

        <meta-data android:name="com.google.android.gms.version"

            android:value="@integer/google_play_services_version"/>

 

        <service android:name="com.bitdrome.bdarenaconnector.gcm.PushService"/>

 

        <receiver

            android:name="com.bitdrome.bdarenaconnector.gcm.GcmBroadcastReceiver"

            android:permission="com.google.android.c2dm.permission.SEND">

            <intent-filter>

                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>

                <category android:name="<your.package.name>"/>

            </intent-filter>

        </receiver>

 

        <!-- Use the built-in Broadcast Receiver -->

        <receiver android:name="com.bitdrome.bdarenaconnector.gcm.ArenaPushBroadcastReceiver" 

            android:exported="false">

            <intent-filter>

                <action android:name="com.bitdrome.bdarenaconnector.push.intent.OPEN"/>

            </intent-filter>

        </receiver>

 

        <!-- Use this to customize the notification icon -->

        <meta-data

            android:name="com.bitdrome.bdarenaconnector.push.notification_icon"

            android:resource="@drawable/ic_notification"/>

 

    </application>

 

 

 In the onCreate method of the MainActivity class you have to perform the Arena authentication:

 

 

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

 

        BDArenaConnector.initializeWithAppKey(this,

            "<YOUR_APP_KEY>", false);

 

        BDArenaConnector.getInstance().registerEventsObserver(new ArenaHandler());

        BDArenaConnector.getInstance().requestAuth();

    }

 

 

With these basic calls, the application will be completely able

to manage incoming push notifications. For the sending operations, two methods are available

through the BDArenaPush class: sendPushToPlayer and sendPushToChannel

   

Moreover, the local player can subscribe and unsubscribe to and from channels simply calling 

subscribeToChannel and unsubscribeFromChannel methods.

  

Sample project

Download the sample project for this tutorial.