Android SDK - the app hoshies

knapsackyarnMobile - sans fil

14 déc. 2013 (il y a 7 années et 7 mois)

880 vue(s)

Android SDK
Android SDK
Integrating Push Messaging into your
Integrating Push Messaging into your
To get started with Push Messaging (C2DM) in your Android app, you'll need to
setup the Android SDK in your app as described in
Android SDK - Integration
into your Android Project
Google Account
Google Account
Create a Google Account if you don't have one already. This account will
be associated with your app. You'll need to provide the account E-Mail
address and password in the App Service Backend, so you might want to
register a separate account besides your private or business account.
Register your Google Account for C2DM on the "Sign Up for Android Cloud
to Device Messaging" page:
Once your Google Account is approved, head over to the App Service
Create a new app or select "Edit" app from the "Apps" Overview page
Enter your E-Mail address and password in the "Google C2DM Account
Settings" section
This concludes the App Service Backend configuration
Setting up the app
Setting up the app
Essentially there are three things you need to do in order to get Push
Messaging working in your app. First off, you need a generic Broadcast
Receiver for the actual receiving of a Push Message and secondly you need
an individual Service class to handle the received Push Message. Lastly the
app needs to register itself with the C2DM service.
The Receiver classes are included in the apphoshies.jar Version 1.0.10 and
higher. Please upgrade your jar file or download the Receiver classes here:
Just extract the Zip file and drag and drop the folder into your app's src
Then you need to implement your own Service class within your app's
package src tree:
You can find an example implementation here:
The lines you need to edit are marked with a TODO comment.
: The Service class needs to be in your root package. It will not
work if it's in a subpackage.
The Service class provides methods for device registration and
unregistration and also for receiving messages.
You can highly customize the
The next step is to register the Receiver and Service class in your
configuration file:
<service android:name=".C2DMReceiver" />



android:name="" />
<category android:name="<YOUR APP PACKAGE>" />

android:name="" /\>

<category android:name="<YOUR APP PACKAGE>" /\>
Please insert the package name of your App.
Also you need to add these additional
to your
configuration file:
<uses-permission android:name="android.permission.GET_ACCOUNTS"


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

<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="<YOUR APP


android:protectionLevel="signature" />
<uses-permission android:name="<YOUR APP

PACKAGE>.permission.C2D_MESSAGE" />

android:name="" />
Please insert the package name of your app.
Lastly add this line of code to the
method of your main activity

With this in place you should now be able to receive Push Messages in your
Android app. There are two ways to create Push Messages:
From the App Service Backend
To send a message to your Android device (not the Simulator), log
into the App Service Backend
Select the app in the Apps Overview
Select your Development device and click
Send Message to
Enter your message and click Send
Alternatively you can visit the
section of your app and
send a message to all devices
Via the Message API
Checkout the Ruby Client Library:
Back to Overview