Android 클라우드를 기기 메시지로 보내려고합니다. 앱을 등록하는 데 문제가 있습니다. 오류 발생하기 com.google.process.gapps asyncFetch : no username. 내가Android 클라우드를 기기 메시징
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>