Android SDK - the app hoshies

knapsackyarnΚινητά – Ασύρματες Τεχνολογίες

14 Δεκ 2013 (πριν από 3 χρόνια και 9 μήνες)

145 εμφανίσεις

Android SDK
Android SDK
Integrating Push Messaging into your
Integrating Push Messaging into your
app
app
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:
http://code.google.com/intl/de-DE/android/c2dm/signup.html
Once your Google Account is approved, head over to the App Service
Backend
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:
http://dl.dropbox.com/u/757246/com.google.android.c2dm.zip
Just extract the Zip file and drag and drop the folder into your app's src
tree.
Then you need to implement your own Service class within your app's
package src tree:
You can find an example implementation here:
https://gist.github.com/dda1e7e1a6b749870343
The lines you need to edit are marked with a TODO comment.
Important
Important
: 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
onMessage
method.
The next step is to register the Receiver and Service class in your
AndroidManifest.xml
configuration file:
<service android:name=".C2DMReceiver" />
<receiver

android:name="com.google.android.c2dm.C2DMBroadcastReceiver"

android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action

android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<YOUR APP PACKAGE>" />
</intent-filter>
<intent-filter>
<action

android:name="com.google.android.c2dm.intent.REGISTRATION" /\>

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

/>
<uses-permission

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

PACKAGE>.permission.C2D_MESSAGE"

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

PACKAGE>.permission.C2D_MESSAGE" />
<uses-permission

android:name="com.google.android.c2dm.permission.RECEIVE" />
Please insert the package name of your app.
Lastly add this line of code to the
onCreate
method of your main activity
(LAUNCHER):
C2DMessaging.register(this,

"YOUR_GOOGLE_ACCOUNT_EMAIL@googlemail.com");
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
Devices
Select your Development device and click
Send Message to
Device
Enter your message and click Send
Alternatively you can visit the
Messages
section of your app and
send a message to all devices
Via the Message API
Checkout the Ruby Client Library:
https://github.com/apphoshies/apphoshies-ruby-client
Back to Overview