任何人做C2DM在Android [英] Anyone doing C2DM on Android

查看:108
本文介绍了任何人做C2DM在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序来实现C2DM。是否有任何人谁也这样做呢?请help..some教程将是非常有益的或者如果你已经完成了你的C2DM实现,那么一个教程超过AP preciated。

I need to implement c2dm in my app. Is there anyone who is also doing this? Please help..some tutorials will be very helpful OR if you have completed your c2dm implementation then a tutorial is more than appreciated.

请帮忙。

推荐答案

我继续下载了Chrome2Phone源$ C ​​$ C Android和理解它是如何工作,通过这个例子,我过的最麻烦实施的服务器端该应用程序。

I went ahead and downloaded the Chrome2Phone source code for android and understood how it works through that example, I had the most trouble implementing the server side of the App.

从这里下载: HTTP://$c$c.google.com/p/chrometophone/source /结帐

或svn的:

svn checkout http://chrometophone.googlecode.com/svn/trunk/ chrometophone-read-only

基本的东西,你应该明白。

Basic things you should understand.

在C2DMBaseReciever类有:

In the C2DMBaseReciever class you have:

@Override
    public final void onHandleIntent(Intent intent) {
        try {
            Context context = getApplicationContext();
            if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
                handleRegistration(context, intent);
            } else if (intent.getAction().equals(C2DM_INTENT)) {
                onMessage(context, intent);
            } else if (intent.getAction().equals(C2DM_RETRY)) {
                C2DMessaging.register(context, senderId);
            }
        } finally {
            //  Release the power lock, so phone can get back to sleep.
            // The lock is reference counted by default, so multiple 
            // messages are ok.

            // If the onMessage() needs to spawn a thread or do something else,
            // it should use it's own lock.
            mWakeLock.release();
        }
    }

此方法临危从C2DM服务的意图和处理它们。

This method recieves the intents from the C2DM service and handles them.

在handleRegistration方法,你会看到一些code,看起来像:

In the handleRegistration method you will see some code that looks like:

} else {
            try {
                onRegistrered(context, registrationId);
                C2DMessaging.setRegistrationId(context, registrationId);
                //Add some code here to send your server the registration ID for this phone.
            } catch (IOException ex) {
                Log.e(TAG, "Registration error " + ex.getMessage());
            }
        }

您那么必须使用谷歌的OAuth登录服务到你的服务器注册到服务,一旦做到这一点,你可以发送邮件。当我在测试我使用卷曲发送HTTP POST请求到服务器。

You then have to use the google oAuth login service to register your server to the service, once that is done you can send a message. When I was testing I was using curl to send http post requests to the server.

要在服务器中注册:

curl https://www.google.com/accounts/ClientLogin -d Email=theEmailYouWhitelisted -d Passwd=pass****word -d accountType=HOSTED_OR_GOOGLE -d source=Google-cURL-Example -d service=ac2dm

您将获得与认证ID的消息。然后你使用它来发送邮件。要发送信息的使用:

You will get a message with an auth id. You then use that to send the messages. To send a message use:

curl --header "Authorization: GoogleLogin auth=**authFromRegistrationAbove**" "https://android.apis.google.com/c2dm/send" -d registration_id=**phoneRegistrationId(reciever)** -d "data.message=StringToPass" -d collapse_key=something -k

下载卷曲的: 卷曲

Download curl from: CURL

希望这有助于。

这篇关于任何人做C2DM在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆