0

I am implementing Couchbase lite with my Android app and I found that the better way to use Couchbase lite sync for pull is to use GCM and not the continuous pull. I was going through the tutorial here and the same app's repo is here.

As mentioned in the repo's readme, I need to use the Notification worker binary from this repo.

I figured out all the things how it works. And also successfully run the sample app using my own sync gateway. But unable to get how can I get the Notification worker thread work for my application.

This notification worker binary communicates with sync gateway as it mentioned here : http://www.slideshare.net/droidconae/droidcon-dubai/32

How can I make it to work for my android app? And what is the actual role it plays to get the changes and how it decides to whom it needs to send the sync request?

Any reference or guide would be very helpful.

Thanks in advance.

kirtan403
  • 7,293
  • 6
  • 54
  • 97

1 Answers1

0

How can I make it to work for my android app?

You would first need to create a Google API project on the developer console and can follow the guide

Then modify your Android.Manifest.xml file from your Android project with the required permissions where it should look like this:

<manifest package="com.couchbase.todolite"> // ...

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

<permission android:name="com.couchbase.todolite.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.couchbase.todolite.permission.C2D_MESSAGE" />

<application android:name="com.couchbase.todolite.Application"> // ...

    /* ... activities ... */

    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.couchbase.todolite" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmMessageHandler" />
</application>

Follow this guide in terms of setting up GCM within your app and long with the instructions to handle the Sync notification on the Android client side.

You mentioned:

And what is the actual role it plays to get the changes and how it decides to whom it needs to send the sync request?

The GCM here is used to trigger the fetching of data from the server side. A request to the GCM servers is provided along with the message to send and the address to send to on the app client side.

sweetiewill
  • 570
  • 2
  • 10
  • I know this thing. This all is mentioned in the tutorial i mentioned in the question. How can I handle the changes on sync gateway with the GCM. The notification worker binary in the example project checks when there are changes on the sync gateway and send puch msges to specific client devices to start sync. How can I achieve that in sync gateway with my own notification worker binary that handles what is going in sync gateway? – kirtan403 Jan 22 '16 at 04:17
  • 1
    The post was published before the 1.1 release. The webhook feature available since then makes this easier (http://blog.couchbase.com/sync-gateway-webhooks). I would use that instead of listening on the changes feed. Secondly, you can use something like node-gcm (https://github.com/ToothlessGear/node-gcm) to put together a NodeJS server (maybe using Express) to receive the webhook payload and send the notification. – jamiltz Jan 29 '16 at 18:08