注册Android应用程序与C2DM [英] Register the Android App with C2DM
本文介绍了注册Android应用程序与C2DM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的版本8的仿真器,当我试图注册的Android应用程序,然后它会给出空注册ID。请帮我解决这个问题。我如何注册C2DM.My code中的Android应用程序的注册应用程序。
意图registrationIntent =新的意向书(com.google.android.c2dm.intent.REGISTER);
registrationIntent.putExtra(应用程序,PendingIntent.getBroadcast(开始code.this,0,新的意向(),0)); //样板
registrationIntent.putExtra(发件人,12786@gmail.com);
startService(registrationIntent);
handleRegistration(getApplicationContext(),registrationIntent);
私人无效handleRegistration(上下文的背景下,意图意图){
字符串登记= intent.getStringExtra(registration_id);
如果(intent.getStringExtra(错误)!= NULL){
//注册失败,应稍后重试。
Log.e(错误,错误);
}否则,如果(intent.getStringExtra(未登记)!= NULL){
//注销完成后,从授权发送新邮件将被拒绝
Log.e(未注册,未登记);
}否则,如果(注册!= NULL){
//发送注册ID的第三方站点的,用于发送的消息。
//这应在一个单独的线程来实现。
//完成后,请记住,所有注册完成。
Log.e(注册,注册);
}
}
解决方案
根据我的经验,你需要添加一个谷歌帐户,你的模拟器。
您只能使用谷歌的目标的API这样做8,而不是Android 2.2的。
I am using the Emulator of version 8. and when i am trying to register the Android Application then it will gives the null registration ID. Please help me to resolve this issue. How can i register the Android Application with C2DM.My code is to register the App.
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(startCode.this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", "12786@gmail.com");
startService(registrationIntent);
handleRegistration(getApplicationContext(), registrationIntent);
private void handleRegistration(Context context, Intent intent) {
String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null) {
// Registration failed, should try again later.
Log.e("ERROR", "ERROR");
} else if (intent.getStringExtra("unregistered") != null) {
// unregistration done, new messages from the authorized sender will be rejected
Log.e("unregistered", "unregistered");
} else if (registration != null) {
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
Log.e("registration", registration);
}
}
解决方案
Based on my experience, you need to add a google account in your emulator.
You can only do so with target of Google APIs 8, not Android 2.2.
这篇关于注册Android应用程序与C2DM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文