Android C2DM hello world失败,注册时出现404错误
我正在尝试使用Android C2DM服务测试基本功能。我遵循了这里找到的示例源: 下面是尝试注册的主要活动Android C2DM hello world失败,注册时出现404错误,android,android-c2dm,Android,Android C2dm,我正在尝试使用Android C2DM服务测试基本功能。我遵循了这里找到的示例源: 下面是尝试注册的主要活动 public class C2DMClientActivity extends Activity { public final static String AUTH = "authentication"; // Example Activity to trigger a request for a registration ID to the Google // server @O
public class C2DMClientActivity extends Activity {
public final static String AUTH = "authentication";
// Example Activity to trigger a request for a registration ID to the Google
// server
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void register(View view) {
Log.w("C2DM", "start registration process");
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.putExtra("app",
PendingIntent.getBroadcast(this, 0, new Intent(), 0));
// Sender currently not used
intent.putExtra("sender", "nonsense@gmail.com");
startService(intent);
}
public void showRegistrationId(View view) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
String string = prefs.getString(AUTH, "n/a");
Toast.makeText(this, string, Toast.LENGTH_LONG).show();
Log.d("C2DM RegId", string);
}
}
记录cat结果:
01-01 02:13:00.536: E/HttpResponse(670): <html><head>
01-01 02:13:00.536: E/HttpResponse(670): <meta http-equiv="content-type" content="text/html;charset=utf-8">
01-01 02:13:00.536: E/HttpResponse(670): <title>404 Not Found</title>
01-01 02:13:00.536: E/HttpResponse(670): </head>
01-01 02:13:00.536: E/HttpResponse(670): <body text=#000000 bgcolor=#ffffff>
01-01 02:13:00.536: E/HttpResponse(670): <h1>Error: Not Found</h1>
01-01 02:13:00.536: E/HttpResponse(670): <h2>The requested URL <code>/register</code> was not found on this server.</h2>
01-01 02:13:00.536: E/HttpResponse(670): <h2></h2>
01-01 02:13:00.536: E/HttpResponse(670): </body></html>
我还可以提供其他信息吗?请告诉我您在这里发布的代码与您粘贴的错误日志无关 查看教程网站,在设备上成功注册后,它会将信息发送到您自己的服务器 HttpPost=新的HttpPost(“http://your_url/register");
看起来您忘记创建/注册路径了显示您的清单。上次我的C2DM实现失败,因为我在清单中定义了错误的包。