Notification Push avec GCM
Bonjour,
je suis entrain de développer une application, le but étant de recevoir des "push notifications" et sa fait maintenant 3 jours que je suis bloqué et je n'arrive pas à m'en sortir. j'ai parcouru tous les tutos présents sur internet mais sans espoir...:aie:
Voici la démarche que j'ai suivi:
-Vous trouverez le code un peu plus loin-
I-coté serveur:
1-J'ai ouvert gcm-demo-server\WebContent\WEB-INF\classes\api à l'aide
d'unblock note j'ai changer la "api key" par la mienne.
2-j'ai executer "ant war" depuis l'invite de commande et en se placant
dans gcm-demo-server
3-j'ai copier le fichier dist\gcm-demo.war dans le fichier webapps de tomcat
4-Enfin je lance le serveur dans un navigateur en saisissant:
http://localhost:8080/gcm-demo
II-Coté client:
Dans la classe CommonUtilities.java j'ai modifié les champs suivants:
1- static final String SERVER_URL = "http://localhost:8080/gcm-demo/home";
2- static final String SENDER_ID = "876836784656";
qui sont respectivement l'url de mon serveur et mon Id sender. 8-)
Enfin quand je lance le serveur il affiche "No device registred", puis je lance l'app a partir de mon smartphone elle affiche "device is already registred" mais finalement quand j'actualise le serveur, il se passe rien et marque "No device registred", cependant il doit afficher le téléphone enregistré et un button me permettant d'envoyer une "push notification" :cry:
PLEAAAZ help!!
Avant de vous laisser avec le code je promet à celui qui m'aide un bisou ;)
Code de l'app:
- le code et les classes que j'ai utilisé ICI
- le Manifest:
Code:
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gcm.demo.app"
android:versionCode="1"
android:versionName="1.0" >
<!-- 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"/>
<!-- 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="com.google.android.gcm.demo.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission
android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Main activity. -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".DemoActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
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="com.google.android.gcm.demo.app" />
</intent-filter>
</receiver>
<!--
Application-specific subclass of GCMBaseIntentService that will
handle received messages.
By default, it must be named .GCMIntentService, unless the
application uses a custom BroadcastReceiver that redefines its name.
-->
<service android:name=".GCMIntentService" />
</application>
</manifest> |
Code serveur:
-Toutes les classes sont ICI
Et un grand Merci à tous ceux qui ont pris la peine de jeter un coup d’œil à mon sujet et à ceux qui pourront m'aider :oops: .