大佬教程收集整理的这篇文章主要介绍了android – GCM注册:移动网络上不提供服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
奇怪的是,当设备在Wifi上时,代码运行正常.当它在移动网络上时几乎总是失败(90%).
互联网上的移动数据工作正常,其他服务器操作正在运行,虽然它们比Wifi慢一点.
我尝试添加@L_450_3@简单的循环(不是指数等待)以在睡眠间隔后继续重试,但没有运气.
片刻我在操作(GCM注册)上切换Wifi成功.
请帮忙.
****更新更多信息** **:我在我的设备上测试了GCM Demo,它也有同样的问题.移动数据失败,在Wifi上运行良好.
失败的设备是注3,目标版本是4.4.2.
奇怪的是,相同的代码在其他设备上运行良好(版本2.3.6)
GCM注册
try { String sdeviceid=null; if (checkPlayservices()) { GoogleCloudmessaging gcm = GoogleCloudmessaging.geTinstance(context); sdeviceid = getRegistrationId(context); if (sdeviceid==null) { for(int i=0;i<60;i++){ try{ sdeviceid= gcm.register(SENDER_ID); break; }catch(IOException E){ Thread.sleep(2000); conTinue; } } // Persist the regID - no need to register again. storeRegistrationId(context,sdeviceid); } sdeviceid = getRegistrationId(context); if (sdeviceid==null) { error=true; throw new Exception("GCM Error"); }@H_874_19@显示XML
<!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.planetapp.schoolink" /> </intent-filter> </receiver> <service android:name="com.planetapp.schoolink.GCMIntentservice" />@H_874_19@广播接收器
public class GCMBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { System.out.println("++++++++++++ON RECEIVE"); String regId = intent.getExtras().getString("registration_id"); if(regId != null && !regId.equals("")) { /* Do what ever you want with the regId eg. send it to your server */ System.out.println("++++++++++++ID RECEIVED++++++++++++"+regId); } }@H_874_19@}
以上是大佬教程为你收集整理的android – GCM注册:移动网络上不提供服务全部内容,希望文章能够帮你解决android – GCM注册:移动网络上不提供服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。