2011-11-25 82 views
0

正在尝试使用Android Cloud到设备消息传递。我有问题注册应用程序。获取错误com.google.process.gapps asyncFetch:无用户名。我已经包含下面Android Cloud到设备消息传递

Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER"); 
intent.putExtra("app",PendingIntent.getBroadcast(this, 0, new Intent(), 0)); 
intent.putExtra("sender", "[email protected]"); 
startService(intent); 

我的注册/接收我的代码:

package com.mpest; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 
import android.widget.Toast; 

public class MyC2dmReceiver extends BroadcastReceiver{ 

private static String KEY = "c2dmPref"; 
    private static String REGISTRATION_KEY = "registrationKey"; 

    private Context context; 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     this.context = context; 
      Log.i("aaa", "jnh"); 
     if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) { 
      handleRegistration(context, intent); 
     } 
     } 
     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.d("c2dm", "registration failed"); 
      String error = intent.getStringExtra("error"); 
      if(error.equals("SERVICE_NOT_AVAILABLE")){ 
       Log.d("c2dm", "SERVICE_NOT_AVAILABLE"); 
      }else if(error.equals("ACCOUNT_MISSING")){ 
       Log.d("c2dm", "ACCOUNT_MISSING"); 
      }else if(error.equals("AUTHENTICATION_FAILED")){ 
       Log.d("c2dm", "AUTHENTICATION_FAILED"); 
      }else if(error.equals("TOO_MANY_REGISTRATIONS")){ 
       Log.d("c2dm", "TOO_MANY_REGISTRATIONS"); 
      }else if(error.equals("INVALID_SENDER")){ 
       Log.d("c2dm", "INVALID_SENDER"); 
      }else if(error.equals("PHONE_REGISTRATION_ERROR")){ 
       Log.d("c2dm", "PHONE_REGISTRATION_ERROR"); 
      } 
      } 
      else if (registration != null) { 
      Log.d("c2dm", registration); 
      //Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit(); 
       // editor.putString(REGISTRATION_KEY, registration); 
      //editor.commit(); 
      // 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. 
     } 
    } 

     private void handleMessage(Context context, Intent intent) 
    { 
      String mywish= intent.getStringExtra("wishes");  
       Toast.makeText(context,"my wishes : "+mywish,1).show(); 

     //Do whatever you want with the message 
    } 
} 

我manifeast

  <!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it --> 
    <receiver android:name=".C2DMReceiver" 
    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.mpest.MyC2dmReceiver" /> 
     </intent-filter> 
     <!-- Receive the registration id --> 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="com.mpest.MyC2dmReceiver" /> 
     </intent-filter> 
    </receiver> 

回答

0

添加一些权限,您的清单

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<permission android:name="com.mpest.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="com.mpest.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
0

您需要有一个积极有效的谷歌我想你的模拟器帐户。 :)

相关问题