Android C2DMRegister.25寄存器:http错误401

Android C2DMRegister.25寄存器:http错误401,android,android-c2dm,Android,Android C2dm,我试图在本教程中使用C2DM客户端:http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html 我为客户端使用的代码与教程代码略有不同: 我只更改了包名,我将两个包合并在一个包中,com.DemoC2DM,我更改了清单中的一些行,以使代码与新的和唯一的包一起工作,但可能我在清单更改行中做了一些错误,因为我在尝试向客户机获取注册ID时遇到了以下错误: 01-16 12:45:52.133: ERROR/Supe

我试图在本教程中使用C2DM客户端:http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html

我为客户端使用的代码与教程代码略有不同:

我只更改了包名,我将两个包合并在一个包中,com.DemoC2DM,我更改了清单中的一些行,以使代码与新的和唯一的包一起工作,但可能我在清单更改行中做了一些错误,因为我在尝试向客户机获取注册ID时遇到了以下错误:

01-16 12:45:52.133: ERROR/Super(1517): Starting registration
01-16 12:45:52.375: DEBUG/GoogleLoginService(1226): onBind: Intent { act=android.accounts.AccountAuthenticator cmp=com.google.android.gsf/.loginservice.GoogleLoginService }
01-16 12:45:53.640: DEBUG/dalvikvm(1226): GC_FOR_MALLOC freed 7811 objects / 420368 bytes in 53ms
01-16 12:45:53.640: DEBUG/NativeCrypto(1226): Freeing OpenSSL session
01-16 12:45:53.945: WARN/DefaultRequestDirector(1226): Authentication error: Unable to respond to any of these challenges: {}
01-16 12:45:53.945: DEBUG/C2DMRegistrar(1226): [C2DMRegistrar.25] register: http error 401
01-16 12:45:53.945: ERROR/C2DMRegistrar(1226): [C2DMReg] handleRequest caught org.apache.http.auth.AuthenticationException
这是我舱单的代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.DemoC2DM" android:versionCode="1"
    android:versionName="1.0">
    <permission android:name="com.DemoC2DM.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.DemoC2DM.permission.C2D_MESSAGE" />
    <!-- Permissions -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="RegisterActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".C2DMReceiver" />


        <!-- Only C2DM servers can send messages for the app. If permission is 
            not set - any other app can generate it -->
        <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <!-- Receive the actual message -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="de.vogella.android.c2dm" />
            </intent-filter>
            <!-- Receive the registration id -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="de.vogella.android.c2dm" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

您好,只需在清单文件中进行以下更改,然后尝试使用

 <!-- Only C2DM servers can send messages for the app. If permission is 
        not set - any other app can generate it -->
    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.DemoC2DM" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.DemoC2DM" />
        </intent-filter>
    </receiver>

我得到了异常如果我做了你的更改,我在我的问题底部添加了异常,请检查它。在你的项目中找不到com.google.android.c2dm.c2dm这个类,所以你得到了异常。在做了更改后,请清理你的项目一次,这样它将生成R.java文件,然后检查againi是否做了,我仍然收到同样的异常:01-16 14:12:53.156:ERROR/AndroidRuntime1645:Caused:java.lang.ClassNotFoundException:com.google.android.c2dm.C2DMBroadcastReceiver in loader dalvik.system.PathClassLoader[/data/app/com.DemoC2DM-1.apk]你能给我发邮件给我那个演示吗?我会检查一下,然后返回使用,您可以使用:import/general/existing projects-into-workspace将其导入eclipse。您必须先解压缩zip文件
01-16 13:16:39.187: DEBUG/C2DMRegistrar(1226): [C2DMRegistrar.25] register: http error 401
01-16 13:16:39.187: ERROR/C2DMRegistrar(1226): [C2DMReg] handleRequest caught org.apache.http.auth.AuthenticationException
01-16 13:16:39.218: DEBUG/GoogleLoginService(1226): onBind: Intent { act=android.accounts.AccountAuthenticator cmp=com.google.android.gsf/.loginservice.GoogleLoginService }
01-16 13:16:39.289: WARN/ActivityManager(1086): Unable to start service Intent { act=com.motorola.motosync.service.intent.action.CHECK_PING flg=0x4 cmp=com.motorola.motosync/.service.EasService (has extras) }: not found
01-16 13:16:39.304: DEBUG/GoogleLoginService(1226): onBind: Intent { act=android.accounts.AccountAuthenticator cmp=com.google.android.gsf/.loginservice.GoogleLoginService }
01-16 13:16:40.218: DEBUG/dalvikvm(1226): GC_FOR_MALLOC freed 8422 objects / 453352 bytes in 71ms
01-16 13:16:40.523: DEBUG/AndroidRuntime(1535): Shutting down VM
01-16 13:16:40.523: WARN/dalvikvm(1535): threadid=1: thread exiting with uncaught exception (group=0x4001d7e0)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535): FATAL EXCEPTION: main
01-16 13:16:40.539: ERROR/AndroidRuntime(1535): java.lang.RuntimeException: Unable to instantiate receiver com.google.android.c2dm.C2DMBroadcastReceiver: java.lang.ClassNotFoundException: com.google.android.c2dm.C2DMBroadcastReceiver in loader dalvik.system.PathClassLoader[/data/app/com.DemoC2DM-2.apk]
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.os.Looper.loop(Looper.java:123)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at java.lang.reflect.Method.invokeNative(Native Method)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at java.lang.reflect.Method.invoke(Method.java:521)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at dalvik.system.NativeStart.main(Native Method)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535): Caused by: java.lang.ClassNotFoundException: com.google.android.c2dm.C2DMBroadcastReceiver in loader dalvik.system.PathClassLoader[/data/app/com.DemoC2DM-2.apk]
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2780)
01-16 13:16:40.539: ERROR/AndroidRuntime(1535):     ... 10 more
01-16 13:16:40.562: WARN/ActivityManager(1086):   Force finishing activity com.DemoC2DM/.RegisterActivity
 <!-- Only C2DM servers can send messages for the app. If permission is 
        not set - any other app can generate it -->
    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.DemoC2DM" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.DemoC2DM" />
        </intent-filter>
    </receiver>