我正在开发GCM应用并收到“错误:AUTHENTICATION_FAILED”。我,我使用我的三星标签设备。我的代码如下:
private void registerInBackground() {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
Log.i(TAG, "11111");
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
Log.i(TAG, "11dfsfsd111");
}
Log.i(TAG, "11dfsfsd111fsdfsdf");
regid = gcm.register(SENDER_ID);
Log.i(TAG, "id = :"+regid);
Log.i(TAG, "2222");
msg = "Device registered, registration ID=" + regid;
// You should send the registration ID to your server over HTTP, so it
// can use GCM/HTTP or CCS to send messages to your app.
// sendRegistrationIdToBackend();
// For this demo: we don't need to send it because the device will send
// upstream messages to a server that echo back the message using the
// 'from' address in the message.
// Persist the regID - no need to register again.
// storeRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
Log.i(TAG, "sdfdsfs:" + msg);
mDisplay.append(msg + "\n");
}
}.execute(null, null, null);
}
i当控件进入postExecute函数并打印“msg”变量时,获取此消息。我搜索了错误,发现这个错误是由于gmail sync acount的密码错误,但我检查了它,我的密码是正确的。请帮助
答案 0 :(得分:1)
public void registerClient() {
try {
// Check that the device supports GCM (should be in a try / catch)
GCMRegistrar.checkDevice(viewLogin);
// Check the manifest to be sure this app has all the required
// permissions.
GCMRegistrar.checkManifest(viewLogin);
// Get the existing registration id, if it exists.
regId = GCMRegistrar.getRegistrationId(viewLogin);
if (regId.equals("")) {
registrationStatus = "Registering...";
// register this device for this project
GCMRegistrar.register(viewLogin, GCMIntentService.PROJECT_ID);
regId = GCMRegistrar.getRegistrationId(viewLogin);
registrationStatus = "Registration Acquired";
// This is actually a dummy function. At this point, one
// would send the registration id, and other identifying
// information to your server, which should save the id
// for use when broadcasting messages.
} else {
registrationStatus = "Already registered";
}
Log.d(TAG, regId);
sendRegistrationToServer();
} catch (Exception e) {
e.printStackTrace();
registrationStatus = e.getMessage();
}
Log.d(TAG, registrationStatus);
// This is part of our CHEAT. For this demo, you'll need to
// capture this registration id so it can be used in our demo web
// service.
}
请使用此..在我的项目中工作。 添加你的manifestfile:
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
答案 1 :(得分:0)
我认为您正在使用旧的GCM实现。开发人员站点(http://developer.android.com/google/gcm/client.html)上提供了新的GCM实施代码。帐户身份验证和其他类型的身份验证在此处正确处理