我正在为我的应用程序处理GCM推送通知。 GCM推送通知在Android 4.0.4操作系统设备中运行良好,但在HCL ME U1平板电脑中,它们无法正常工作。在那个HCL平板电脑中,Playstore也无法正常工作。是因为Playstore GCM推送通知在平板电脑中不起作用吗?
任何人都可以指导我如何解决这个问题吗?
答案 0 :(得分:0)
请确保您以这种方式注册并且您的发件人ID正确无误。然后,您将调用对您的类的public final void onHandleIntent(Intent intent)
重写方法的调用,扩展intentservice类。
所以你应该看一下,你在intent.getStringExtra("error");
这里使用onHandleIntent
方法获得的错误信息是try {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
//String regId = GCMRegistrar.getRegistrationId(this);
SharedPreferences sharedPrefs = this.getSharedPreferences(
getApplicationContext().getPackageName(), Context.MODE_PRIVATE);
//String regId = sharedPrefs.getString(myRegKey, "");
//if(regId.equals(""))
{
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", Your sender id here);
startService(registrationIntent);
}
} catch (Exception ex) {
ex.printStackTrace();
}
方法。这将告诉你为什么google cudnt会注册你的设备。
@Override
public final void onHandleIntent(Intent intent) {
try {
String action = intent.getAction();
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(intent);
} else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
onMessage(this, intent);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
protected void handleRegistration(Intent intent) {
String registrationId = intent.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
String unregistered = intent.getStringExtra("unregistered");
//rest of code
}
protected void onMessage(Context context, Intent intent) {
String title = intent.getStringExtra("title");
//rest of code
}
<强> EDIT1 强>
{{1}}
你能告诉我registrationId,error,unregistered的值吗?