1

CdmaCellLocationに関するいくつかのレポートを(同じユーザーから)Google Playで受け取りました:

 java.lang.ClassCastException: android.telephony.cdma.CdmaCellLocation

これは、セルネットワークを使用してユーザーのおおよその位置を報告するサービスです。100%機能しており、このバグに関する他のレポートはありませんでした。ここでは、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();

}

そして最後にGooglePlayの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

あなたはそれが電話プロバイダーの問題だと思いますか、それともタブレットから来ているのですか?

[オフトピック]ちなみに、これをどこでどのように報告できますか:

ここに画像の説明を入力してください

4

2 に答える 2

3
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();

これは危険なキャストです。あなたのコードは、このメソッドが常にのインスタンスを返すことを前提としていますがGsmCellLocation、そうではありません。セルラーネットワークには2つのタイプがあります。GSMおよびCDMA。

電話がCDMAネットワークで実行されているgetCellLocation()場合は、のインスタンスを返しますCdmaCellLocation

telephonyManager.getPhoneType()デバイスで使用されている無線の種類に関する情報を取得するために電話をかけることができます。このメソッドは、次の4つの値のいずれかを返します。

PHONE_TYPE_NONE-デバイスにセルラー無線がありません。たとえば、3Gモデムのないタブレットの場合があります。getCellLocation()を返しnullます。

PHONE_TYPE_GSM-デバイスにはGSM無線があります。安全に電話できます(GsmCellLocation) telephonyManager.getCellLocation();

PHONE_TYPE_CDMA-デバイスにはGSM無線があります。安全に電話できます(CdmaCellLocation) telephonyManager.getCellLocation();

PHONE_TYPE_SIP-デバイスは通信にSIP(Session Initiation Protocol)を使用しています。getCellLocation()を返しnullます。

于 2013-03-03T22:09:17.363 に答える
2

getPhoneType()これを調べると、TelephonyManagerクラスのを使用して電話の種類を判別できます。

私は次のことを試みます:

switch( telephonyManager.getPhoneType() ) {

    case PHONE_TYPE_GSM: {
         // Handle GSM phone
         GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
         break;
    }
    case PHONE_TYPE_CDMA: {
         // Handle CDMA phone
         CdmaCellLocation cellLocation = (CdmaCellLocation) telephonyManager.getCellLocation();
         break;
    }
    default: {
        // can't do cell location
    }
于 2013-03-03T22:12:47.613 に答える