使用GCM,城市飞艇发送推送通知 [英] Using GCM, Urban Airship to send Push Notification
问题描述
我已经建立在谷歌控制台的示例项目。从本网站参照样本,<一个href=\"http://$c$c.google.com/p/blog-samples/downloads/detail?name=gcm_sample_update1.rar&can=2&q=#makechanges\" rel=\"nofollow\">http://$c$c.google.com/p/blog-samples/downloads/detail?name=gcm_sample_update1.rar&can=2&q=#makechanges我得到了我的注册ID。现在我不知道下一步该怎么做,我怎么能在我的应用程序实现推送通知。我想用飞艇城市发送推我的应用程序。我已经创造了城市飞艇一个应用程序,通过给通过谷歌获得控制台的包名,API密钥。到我的服务器我需要发送的APID得到的消息。但我不知道如何获得APID。
I have created a sample project in Google Console. Referring the sample from this site, http://code.google.com/p/blog-samples/downloads/detail?name=gcm_sample_update1.rar&can=2&q=#makechanges I got my registration Id. Now I don't know what to do next, how I can implement push notification in my app. I want to use Urban Airship to send push to my app. I have created a app in Urban Airship, by giving the package name, API key obtained through Google console. To my server I need to send the Apid to get the messages. But i don't know how to get the Apid.
推荐答案
据了说明:的 http://developer.android.com/guide/google/gcm/gs.html
编写Android应用程序
您必须下载并添加GCM库。
然后,使舱单更改:
It is explained here: http://developer.android.com/guide/google/gcm/gs.html Writing the Android Application You have to download and add gcm libraries. Then make changes in manifest:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="xx"/>
和
<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" />
在my_app_package插入你的包名。
添加其他权限。
inserting Your package name in "my_app_package". Add other permissions
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- 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" />
接收
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my_app_package" />
</intent-filter>
</receiver>
写一遍你的包名my_app_package。
然后,声明你的服务
Again write Your package name in "my_app_package". Then declare your service
<service android:name=".GCMIntentService" />
您必须创建一个名为GCMIntentService类。这个类将要处理的推送通知。
它应该是这样的:
You have to create a class named GCMIntentService. This class is going to handle the push notifications. It should look like this:
class GCMIntentService extends com.google.android.gcm.GCMBaseIntentService{
public void onRegistered(Context context, String regId){}
public void onUnregistered(Context context, String regId){}
public void onError(Context context, String errorId){}
public void onMessage(Context context, Intent intent){}
}
在的onMessage(),你将不得不处理推送消息。您可以使用通知。
In onMessage() you will have to handle the push message. You can use notifications.
然后在你出发的活动,你将不得不把这个
Then in Your starting Activity you will have to put this
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
在的onCreate()。
SENDER_ID是包含您从谷歌得到了控制台所有的数字字符串。
in onCreate(). SENDER_ID is the String containing all numbers that you got from the google console.
这篇关于使用GCM,城市飞艇发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!