1

システム時刻と GPS ロックから取得した時刻を比較するアプリがあります。HTC One X でアプリを実行すると、正常に動作します。one X は 4.1 を実行しています。HTC Desire C(2.3) でアプリを実行すると、Gps からの時間はシステム時間と同じになります。

たとえば、電話の設定に入り、電話のシステム時刻を 1 時間進むように変更すると、GPS からの時刻にもこれが反映されます。なぜこれが起こるのか誰か教えてください。2.3 を実行している Samsung Ace2 でも動作するため、Android のバージョンではありません。特定のデバイスの問題だと思います。

@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();

                }

            }
4

0 に答える 0