我在Google Play上收到了一些关于CdmaCellLocation的报告(来自同一个用户):
java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation这是一个使用Cell Network报告近似用户位置的服务,请注意它100%为我工作,我没有关于此Bug的任何其他报告,这里是来自onStart()的代码:
public class ServiceLocation extends Service{ int myLatitude , myLongitude; private String str2; static SharedPreferences prefs; private String numtosend; public int onStartCommand(Intent itn,int num1, int num2){ prefs = getSharedPreferences("Preferences", Context.MODE_PRIVATE); if(isAirplaneModeOn(this)){ stopSelf(); } Bundle extras = itn.getExtras(); if(extras.containsKey("ExtraName") != true){ str2 = itn.getStringExtra("Number"); } location(str2); return 0; }这里的位置方法代码:
public void location(String num){ // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT){ numtosend = "Phone Number (If Avaible) : " + " " + telephonyManager.getLine1Number() + " " + " Sim Serial : " + telephonyManager.getSimSerialNumber() + " " + "IMEI : " + telephonyManager.getDeviceId(); } else { numtosend = this.getResources().getString(R.string.txtNoSimCard) + telephonyManager.getDeviceId(); } GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); int cid = cellLocation.getCid(); int lac = cellLocation.getLac(); if(RqsLocation(cid, lac)){ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtGPSPosition) + "(40-250 Meters Accuracy) : "+"http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString(R.string.txtGPSPosition) + "(~300 Meters Accuracy) : " + "http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000) + " " + str2 + " " + numtosend); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { SmsManager.getDefault().sendTextMessage(str2, null, "Impossible to Send a Message to your Emergency Mail Address !", null, null); } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else{ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtInternetOffLocation), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString("Internet Off)); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stopSelf(); }最终来自Google Play的LogCat:
java.lang.RuntimeException: Unable to start service com.xxx.xxx.xxx.ServiceLocation@4051b930 with Intent { cmp=com.xxx.xxx.xxx/.ServiceLocation (has extras) }: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2052) at android.app.ActivityThread.access$2800(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at com.xxx.xxx.xxx.ServiceLocation.location(ServiceLocation.java:83) at com.xxx.xxx.xxx.ServiceLocation.onStartCommand(ServiceLocation.java:53) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039) ... 10 more您认为它是电话提供商的问题,还是来自平板电脑?
[非主题]顺便说一下,在哪里以及如何报告此内容:
I received some Reports on Google Play(from the same User) about CdmaCellLocation :
java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocationthis is a Service that Report the Approximativ User Location using Cell Network , Please Notice that its 100% Working for me and i had not any other Report about this Bug , Here the Code from the onStart() :
public class ServiceLocation extends Service{ int myLatitude , myLongitude; private String str2; static SharedPreferences prefs; private String numtosend; public int onStartCommand(Intent itn,int num1, int num2){ prefs = getSharedPreferences("Preferences", Context.MODE_PRIVATE); if(isAirplaneModeOn(this)){ stopSelf(); } Bundle extras = itn.getExtras(); if(extras.containsKey("ExtraName") != true){ str2 = itn.getStringExtra("Number"); } location(str2); return 0; }Here the location Method Code :
public void location(String num){ // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT){ numtosend = "Phone Number (If Avaible) : " + " " + telephonyManager.getLine1Number() + " " + " Sim Serial : " + telephonyManager.getSimSerialNumber() + " " + "IMEI : " + telephonyManager.getDeviceId(); } else { numtosend = this.getResources().getString(R.string.txtNoSimCard) + telephonyManager.getDeviceId(); } GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); int cid = cellLocation.getCid(); int lac = cellLocation.getLac(); if(RqsLocation(cid, lac)){ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtGPSPosition) + "(40-250 Meters Accuracy) : "+"http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString(R.string.txtGPSPosition) + "(~300 Meters Accuracy) : " + "http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000) + " " + str2 + " " + numtosend); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { SmsManager.getDefault().sendTextMessage(str2, null, "Impossible to Send a Message to your Emergency Mail Address !", null, null); } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else{ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtInternetOffLocation), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString("Internet Off)); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stopSelf(); }And finaly The LogCat From Google Play :
java.lang.RuntimeException: Unable to start service com.xxx.xxx.xxx.ServiceLocation@4051b930 with Intent { cmp=com.xxx.xxx.xxx/.ServiceLocation (has extras) }: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2052) at android.app.ActivityThread.access$2800(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at com.xxx.xxx.xxx.ServiceLocation.location(ServiceLocation.java:83) at com.xxx.xxx.xxx.ServiceLocation.onStartCommand(ServiceLocation.java:53) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039) ... 10 moreDo you Think its a Problem with the Phone Provider , or if its come from Tablet ?
[Off-Topic] By the way , where & how can i Report this :
最满意答案
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();这是一个不安全的演员。 您的代码假定此方法将始终返回GsmCellLocation的实例,但情况并非如此。 有两种类型的蜂窝网络。 GSM和CDMA。
如果手机在CDMA网络上运行,则getCellLocation()将返回CdmaCellLocation的实例。
您可以调用telephonyManager.getPhoneType()以获取有关设备使用的无线电类型的信息。 此方法将返回以下四个值之一:
PHONE_TYPE_NONE - 设备没有蜂窝无线电。 例如,它可能是没有3G调制解调器的平板电脑。 getCellLocation()将返回null 。
PHONE_TYPE_GSM - 该设备具有GSM无线电。 您可以安全地调用(GsmCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_CDMA - 该设备具有GSM无线电。 您可以安全地调用(CdmaCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_SIP - 设备正在使用SIP(会话启动协议)进行通信。 getCellLocation()将返回null 。
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();This is an unsafe cast. Your code assumes that this method will always return an instance of GsmCellLocation but that is not the case. There are two types of cellular networks. GSM and CDMA.
If the phone is running on a CDMA network then getCellLocation() will return an instance of CdmaCellLocation.
You can call telephonyManager.getPhoneType() to get information about the type of the radio used by the device. This method will return one of four values:
PHONE_TYPE_NONE - the device doesn't have a cellular radio. It could be a tablet without a 3G modem for instance. getCellLocation() will return null.
PHONE_TYPE_GSM - the device has a GSM radio. You can safely call (GsmCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_CDMA - the device has a GSM radio. You can safely call (CdmaCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_SIP - the device is using SIP (Session Initiation Protocol) for communication. getCellLocation() will return null.
尝试使用电话类获取单元位置时ClassCastExeption错误(ClassCastExeption Error when Trying to Get Cell Location Using Telephony Class)我在Google Play上收到了一些关于CdmaCellLocation的报告(来自同一个用户):
java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation这是一个使用Cell Network报告近似用户位置的服务,请注意它100%为我工作,我没有关于此Bug的任何其他报告,这里是来自onStart()的代码:
public class ServiceLocation extends Service{ int myLatitude , myLongitude; private String str2; static SharedPreferences prefs; private String numtosend; public int onStartCommand(Intent itn,int num1, int num2){ prefs = getSharedPreferences("Preferences", Context.MODE_PRIVATE); if(isAirplaneModeOn(this)){ stopSelf(); } Bundle extras = itn.getExtras(); if(extras.containsKey("ExtraName") != true){ str2 = itn.getStringExtra("Number"); } location(str2); return 0; }这里的位置方法代码:
public void location(String num){ // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT){ numtosend = "Phone Number (If Avaible) : " + " " + telephonyManager.getLine1Number() + " " + " Sim Serial : " + telephonyManager.getSimSerialNumber() + " " + "IMEI : " + telephonyManager.getDeviceId(); } else { numtosend = this.getResources().getString(R.string.txtNoSimCard) + telephonyManager.getDeviceId(); } GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); int cid = cellLocation.getCid(); int lac = cellLocation.getLac(); if(RqsLocation(cid, lac)){ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtGPSPosition) + "(40-250 Meters Accuracy) : "+"http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString(R.string.txtGPSPosition) + "(~300 Meters Accuracy) : " + "http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000) + " " + str2 + " " + numtosend); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { SmsManager.getDefault().sendTextMessage(str2, null, "Impossible to Send a Message to your Emergency Mail Address !", null, null); } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else{ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtInternetOffLocation), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString("Internet Off)); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stopSelf(); }最终来自Google Play的LogCat:
java.lang.RuntimeException: Unable to start service com.xxx.xxx.xxx.ServiceLocation@4051b930 with Intent { cmp=com.xxx.xxx.xxx/.ServiceLocation (has extras) }: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2052) at android.app.ActivityThread.access$2800(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at com.xxx.xxx.xxx.ServiceLocation.location(ServiceLocation.java:83) at com.xxx.xxx.xxx.ServiceLocation.onStartCommand(ServiceLocation.java:53) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039) ... 10 more您认为它是电话提供商的问题,还是来自平板电脑?
[非主题]顺便说一下,在哪里以及如何报告此内容:
I received some Reports on Google Play(from the same User) about CdmaCellLocation :
java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocationthis is a Service that Report the Approximativ User Location using Cell Network , Please Notice that its 100% Working for me and i had not any other Report about this Bug , Here the Code from the onStart() :
public class ServiceLocation extends Service{ int myLatitude , myLongitude; private String str2; static SharedPreferences prefs; private String numtosend; public int onStartCommand(Intent itn,int num1, int num2){ prefs = getSharedPreferences("Preferences", Context.MODE_PRIVATE); if(isAirplaneModeOn(this)){ stopSelf(); } Bundle extras = itn.getExtras(); if(extras.containsKey("ExtraName") != true){ str2 = itn.getStringExtra("Number"); } location(str2); return 0; }Here the location Method Code :
public void location(String num){ // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT){ numtosend = "Phone Number (If Avaible) : " + " " + telephonyManager.getLine1Number() + " " + " Sim Serial : " + telephonyManager.getSimSerialNumber() + " " + "IMEI : " + telephonyManager.getDeviceId(); } else { numtosend = this.getResources().getString(R.string.txtNoSimCard) + telephonyManager.getDeviceId(); } GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation(); int cid = cellLocation.getCid(); int lac = cellLocation.getLac(); if(RqsLocation(cid, lac)){ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtGPSPosition) + "(40-250 Meters Accuracy) : "+"http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString(R.string.txtGPSPosition) + "(~300 Meters Accuracy) : " + "http://maps.google.com/?q="+String.valueOf((float)myLatitude/1000000) +","+String.valueOf((float)myLongitude/1000000) + " " + str2 + " " + numtosend); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { SmsManager.getDefault().sendTextMessage(str2, null, "Impossible to Send a Message to your Emergency Mail Address !", null, null); } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else{ if(str2.equals("") != true && str2.equals(null) != true) { SmsManager.getDefault().sendTextMessage(num, null, this.getResources().getString(R.string.txtInternetOffLocation), null, null); } if(gmailaccount.equals("") != true && gmailpass.equals(null) != true){ P m = new P(gmailaccount , gmailpass); String[] Mail = {mail}; m.setTo(Mail); m.setFrom("AnonymousMail@gmail.com"); m.setSubject("Location"); m.setBody(this.getResources().getString("Internet Off)); try { if(m.send()){ stopSelf(); } else { if(str2.equals("") != true) { } stopSelf(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } stopSelf(); }And finaly The LogCat From Google Play :
java.lang.RuntimeException: Unable to start service com.xxx.xxx.xxx.ServiceLocation@4051b930 with Intent { cmp=com.xxx.xxx.xxx/.ServiceLocation (has extras) }: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2052) at android.app.ActivityThread.access$2800(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation at com.xxx.xxx.xxx.ServiceLocation.location(ServiceLocation.java:83) at com.xxx.xxx.xxx.ServiceLocation.onStartCommand(ServiceLocation.java:53) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2039) ... 10 moreDo you Think its a Problem with the Phone Provider , or if its come from Tablet ?
[Off-Topic] By the way , where & how can i Report this :
最满意答案
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();这是一个不安全的演员。 您的代码假定此方法将始终返回GsmCellLocation的实例,但情况并非如此。 有两种类型的蜂窝网络。 GSM和CDMA。
如果手机在CDMA网络上运行,则getCellLocation()将返回CdmaCellLocation的实例。
您可以调用telephonyManager.getPhoneType()以获取有关设备使用的无线电类型的信息。 此方法将返回以下四个值之一:
PHONE_TYPE_NONE - 设备没有蜂窝无线电。 例如,它可能是没有3G调制解调器的平板电脑。 getCellLocation()将返回null 。
PHONE_TYPE_GSM - 该设备具有GSM无线电。 您可以安全地调用(GsmCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_CDMA - 该设备具有GSM无线电。 您可以安全地调用(CdmaCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_SIP - 设备正在使用SIP(会话启动协议)进行通信。 getCellLocation()将返回null 。
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();This is an unsafe cast. Your code assumes that this method will always return an instance of GsmCellLocation but that is not the case. There are two types of cellular networks. GSM and CDMA.
If the phone is running on a CDMA network then getCellLocation() will return an instance of CdmaCellLocation.
You can call telephonyManager.getPhoneType() to get information about the type of the radio used by the device. This method will return one of four values:
PHONE_TYPE_NONE - the device doesn't have a cellular radio. It could be a tablet without a 3G modem for instance. getCellLocation() will return null.
PHONE_TYPE_GSM - the device has a GSM radio. You can safely call (GsmCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_CDMA - the device has a GSM radio. You can safely call (CdmaCellLocation) telephonyManager.getCellLocation();
PHONE_TYPE_SIP - the device is using SIP (Session Initiation Protocol) for communication. getCellLocation() will return null.
发布评论