htc desire C Location.getTime()返回系统时间

时间:2013-03-08 09:24:07

标签: android gps location

我有一个应用程序,它将系统时间与从GPS锁定获得的时间进行比较。如果我在我的HTC上运行应用程序One X工作正常。一个X正在运行4.1。如果我在HTC Desire C(2.3)上运行应用程序,则Gps的时间与系统时间相同。

例如,如果我进入手机的设置并将手机的系统时间更改为1小时,则GPS的时间也会反映出来。谁能告诉我为什么会这样。这不是Android的版本,因为它也适用于运行2.3的三星Ace2。我认为这是特定设备的问题。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(NfcBaseActivity.this.getApplicationContext());
        prefsEditor = appSharedPrefs.edit();
        mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //setTitle(getCarername() + " is logged in");
    }




     @Override
    protected void onResume() {
         super.onResume();

         Cursor c = nfcscannerapplication.loginValidate.queryAllFromCompanyIdTable();

            if (c != null && c.getCount() > 0) {

                 mlocListener = new MyLocationListener();

                 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
                     mlocManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, mlocListener, null);


                }else{
                    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
                }

            }






    }




    private class MyLocationListener implements LocationListener {

            @Override
            public void onLocationChanged(Location loc) {

                if(mlocListener != null){

                 mlocManager.removeUpdates(mlocListener);
                 mlocListener = null;

                }

                DateTime dt = new DateTime(loc.getTime());
                DateTimeFormatter df3 = DateTimeFormat.forPattern("yyyy-MM-dd H:mm:ss.SSS");
                String formattedExternalTime = df3.print(dt);
                Log.e(TAG, "formatted ext time = " + formattedExternalTime);
                nfcscannerapplication.setExternalTime(dt);



                String systemExternalTimeTolerance = appSharedPrefs.getString("180", null);
                Log.e(TAG, " comp opt 180 = " + systemExternalTimeTolerance);
                long toleranceInMillis = Long.parseLong(systemExternalTimeTolerance) * 1000 * 60;
                Log.e(TAG, "toleranceInMillis = " + toleranceInMillis);



                long differenceBetweenTimes = nfcscannerapplication.getInternalTime().getMillis() - 
                     nfcscannerapplication.getExternalTime().getMillis();


                Log.e(TAG, "About to make comparison1 differenceBetweenTimes = " + differenceBetweenTimes);
                if(differenceBetweenTimes > toleranceInMillis){

                     DateTimeFormatter df4 = DateTimeFormat.forPattern("yyyy-MM-dd H:mm");
                        String formattedExternalTime2 = df4.print(dt);

                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                            NfcBaseActivity.this);

                        // set title
                        alertDialogBuilder.setTitle("Please set your phone's system time to " + formattedExternalTime2);

                        // set dialog message
                        alertDialogBuilder
                            .setMessage("Click Ok to exit app")
                            .setCancelable(false)
                            .setPositiveButton("Ok",new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {
                                    dialog.cancel();
                                    System.exit(0);
                                }
                              });

                            // create alert dialog
                            AlertDialog alertDialog = alertDialogBuilder.create();

                            // show it
                            alertDialog.show();

                }

                long differenceBetweenTimes2 = nfcscannerapplication.getExternalTime().getMillis() - 
                     nfcscannerapplication.getInternalTime().getMillis();
                Log.e(TAG, "About to make comparison2 differenceBetweenTimes2 = " + differenceBetweenTimes2);
              if(differenceBetweenTimes2 > toleranceInMillis){

                 DateTimeFormatter df4 = DateTimeFormat.forPattern("yyyy-MM-dd H:mm");
                        String formattedExternalTime2 = df4.print(dt);

                 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                            NfcBaseActivity.this);

                        // set title
                 alertDialogBuilder.setTitle("Please set your phone's system time to " + formattedExternalTime2);

                        // set dialog message
                        alertDialogBuilder
                            .setMessage("Click Ok to exit app")
                            .setCancelable(false)
                            .setPositiveButton("Ok",new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {
                                    dialog.cancel();
                                    System.exit(0);
                                }
                              });

                            // create alert dialog
                            AlertDialog alertDialog = alertDialogBuilder.create();

                            // show it
                            alertDialog.show();

                }

            }

0 个答案:

没有答案