Push

Configuration

You must configure you AndroidManifest.xml with these permissions:

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

    <permission android:name="<PACKAGE_NAME>.permission.C2D_MESSAGE"
        android:protectionLevel="normal" />

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

And these receivers and services:

        <!--
        BroadcastReceiver to receive push.
        -->
        <receiver
            android:name="com.movile.kiwi.sdk.push.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >

            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="<PACKAGE_NAME>" />
            </intent-filter>
        </receiver>

        <!--
        BroadcastReceiver to receive and generate notifications.
        -->
        <receiver android:name="com.movile.kiwi.sdk.receiver.NotificationReceiver" android:exported="true">
            <intent-filter>
                <action android:name="<PACKAGE_NAME>.KIWI_PUSH_NOTIFICATION" />
            </intent-filter>
        </receiver>

        <service android:name="com.movile.kiwi.sdk.push.GCMIntentService"
                 android:permission="android.permission.BIND_JOB_SERVICE"/>

NOTE: replace the <PACKAGE_NAME> for your application's package name.

And remember to inform your GCM application Sender Id, in order to kiwi recover the user's push token:

<meta-data android:name="com.movile.kiwi.sdk.applicationSenderId" android:value="id:<value>"/>

NOTE: replace the <value> for the senderId value.

Push Token

The push token is retrieved internally by Kiwi, asynchronously on the SDK initialization. It can be retrieved by calling:

UserInfo userInfo = kiwiSDK.user().retrieveLocalInformation().get();
String pushToken = userInfo.getPushToken();

However, because this value is retrieved asynchronously on the SDK initialization, the push token may be unavailable if the app tries to recover it right after SDK is started. In order to be certain about when the push token is available, one may register a broadcast receiver for the action APP_PACKAGE_NAME.KIWI_PUSH_TOKEN_RECEIVED (Eg: com.movile.turma.monica.KIWI_PUSH_TOKEN_RECEIVED), and extract the parameter KiwiActionParameter.PUSH_TOKEN from the intent extras.

    @Override
    public void onReceive(Context context, Intent intent) {
        String pushToken = intent.getStringExtra(KiwiActionParameter.PUSH_TOKEN.name());
        // ...
    }

Last updated