Django

Solve integrity error duplicate key in Django PostgreSQL

25 Sep , 2015  

This error caused by we’re using database from copy / clone database. The sequences will be mixed-up.
To solved this, just follow this way :

1
2
python manage.py sqlsequencereset <app-name> > app.sql
psql -U username -d database -a -f < app.sql

Then your problem shall gone!

Android

Tutorial Implementation Google Cloud Messaging (GCM) with Django

17 Sep , 2015  

Setup GCM for Android Client and Django in Server require efforts to know how it’s works. Here are simple steps to setup the newest GCM (Google Cloud Messaging) in Android.

To understand about GCM, the flow is :

1. Create a Google APIs GCM project, which generates SENDER_ID and API_KEY for server implementation.

2. An Android app registers the device its running on with GCM, using PROJECT_ID, which generates a registration id. The app should send registration ID to the server.

3. The project’s server code can now send a broadcast message to any registered devices by communicating with the GCM service, using the API KEY.

For the implementation:

1. Dependencies
Update your ADT and Google Play Service packages to be able using the latest GCM. Make sure to import google-play-services lib into your project libraries.

2. AndroidManifest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    <uses -permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses>
    <uses -permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses>

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

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


    <permission android:name="com.polatic.hospitrack.permission.C2D_MESSAGE"
        android:protectionLevel="signature"></permission>

    <uses -permission android:name="com.polatic.hospitrack.gcm.permission.C2D_MESSAGE"></uses>

    ....



        <service android:name="com.polatic.hospitrack.network.GCMListenerInstanceID"
            android:exported="false" >
            <intent -filter>
                <action android:name="com.google.android.gms.iid.InstanceID"></action>
            </intent>
        </service>

        <service android:name="com.polatic.hospitrack.network.GCMListenerService"
            android:exported="false" >
            <intent -filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"></action>
            </intent>
        </service>

        <receiver android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent -filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"></action>

                <category android:name="com.polatic.hospitrack"></category>
            </intent>
        </receiver>

        <service android:name="com.polatic.hospitrack.network.GCMRegistrationIntentService"
            android:exported="false" >
        </service>

More…