Skip to main content

Android : Samsung Galaxy Tabs and Android 2.2 Devices Showing GPs date 1 Day Advance from 1st jan 2012


I have the Galaxy tab GT-P1000 7 inch with firmware version:2.3.3 and Phones running Android 2.2 . In both versions when ever I am trying to get the Time From Gps, Its showing 1 day advance from 1st jan 2012. Same code is working fine on samsung,LG and Motorola Phones.



The Sample code for the App is,




package com.vxceed.dateTime;


import java.util.Calendar;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class SampleDateTimeActivity extends Activity {

private LocationManager locationManager;
private TextView tv;
String varTime="";

/**
* Location Listener
*/
LocationListener locationListener = new LocationListener() {

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

@Override
public void onProviderDisabled(String provider) {
Toast.makeText(SampleDateTimeActivity.this,"GPS off", Toast.LENGTH_SHORT).show();
}

@Override
public void onLocationChanged(Location location) {
setCurrentLocation(location);

}
};



private void setCurrentLocation(Location location) {

varTime=String.valueOf(location.getTime());

}


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, locationListener);

tv=(TextView)findViewById(R.id.textView1);

}


public void refreshTime(View v)
{
String currentGPSTime="";
currentGPSTime=varTime;
if(currentGPSTime.compareTo("")==0)
{
tv.setText("Time Not Available");
}
else
{
Calendar cal=Calendar.getInstance();
cal.setTimeInMillis(new Long(currentGPSTime));

long currentDeviceTime=Calendar.getInstance().getTimeInMillis();

Calendar cal2=Calendar.getInstance();
cal2.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE)-1,cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE));
long currentGPSTime_less_one_Day=cal2.getTimeInMillis();

tv.setText( "GPSTIME:"+cal.getTime().toString() +" \n GPS_TIME_in_Millis:"+varTime+"\nDevice_Time_in_millis:"+String.valueOf(currentDeviceTime) +"\nGPS Time -1 day:"+String.valueOf(currentGPSTime_less_one_Day));
}
}


@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if (locationManager != null && locationListener != null){
locationManager.removeUpdates(locationListener);
locationManager = null;
}
}


}



I have searched the Google and then referring the NMEA official document I figure out How to Use the NMEA data Here is the Working Code for the NMEA listener



NmeaListener nmeaListener = new NmeaListener() {




@Override
public void onNmeaReceived(long timestamp, String nmea) {

parse(nmea);
}
};


private boolean parse(String strNMEA) {

// Discard the sentence if its checksum does not match our calculated
// checksum
boolean bStatus = false;
try {
if (!IsValid(strNMEA)) {

return false;
}
String[] sArrNMEA = strNMEA.split(",");
String strNMEAType = sArrNMEA[0];
if (strNMEAType.equals("$GPRMC")) {

bStatus = ParseGPRMC(sArrNMEA);
} else {

bStatus = false;
}

sArrNMEA = null;
} catch (Exception e) {

}
return bStatus;

}

private boolean ParseGPRMC(String[] sArrNMEA) {

boolean result = false;
try {
if (sArrNMEA.length > 9) {
int Hr = 0;
int Mins = 0;
int Secs = 0;

if (!sArrNMEA[1].equals("")) {

Hr = Integer.parseInt(sArrNMEA[1].substring(0, 2));
Mins = Integer.parseInt(sArrNMEA[1].substring(2, 4));

if (sArrNMEA[1].length() > 6) {

Secs = Integer.parseInt(sArrNMEA[1].substring(4, 6));
} else {
Secs = Integer.parseInt(sArrNMEA[1].substring(4));
}

}
if (!sArrNMEA[9].equals("")) {
int Day = Integer.parseInt(sArrNMEA[9].substring(0, 2));
int Month = Integer.parseInt(sArrNMEA[9].substring(2, 4));
if (Month > 0) {
Month = Month - 1;
}
int Year = Integer.parseInt(sArrNMEA[9].substring(4));
Year = 2000 + Year;

if (!sArrNMEA[1].equals("")) {

Calendar cal = Calendar.getInstance(TimeZone
.getTimeZone("UTC"));
cal.set(Year, Month, Day, Hr, Mins, Secs);

nmeaTime = String.valueOf(cal.getTimeInMillis());

}

}



result = true;
}
} catch (Exception e) {

}

return result;

}

private boolean IsValid(String strNMEA) {
// Compare the characters after the asterisk to the calculation
strNMEA = strNMEA.replace("\r", "");
strNMEA = strNMEA.replace("\n", "");
return strNMEA.substring(0, strNMEA.length())
.substring(strNMEA.indexOf("*") + 1)
.equalsIgnoreCase(GetChecksum(strNMEA));
}


Source: Tips4all
Source: Tips4allSource: CCNA FINAL EXAM

Comments

  1. I've tried to use the NMEA location listener (on a Samsung Galaxy Tab 8.9 with Honeycomb 3.1), but the date I retrieve from it is always 1 day in advance.
    Could you please post the code which solves the issue by means of the NMEA location listener?

    ReplyDelete
  2. This seems to be affecting all stock Samsung firmwares, i am logging a concern with Samsung about this. It seems to be isolated to Samsung devices. So if you can test on another device, or install custom firmware. both of those have worked for me. and your code looks good, nothing wrong there, this is a firmware issue

    EDIT: I have contacted the Korean Engineers - they have said they weren't aware of the problem but have patched and it should be fixed in the latest update for the SGS and other affected products. (unless of course that device hasn't had an update for a while - so not sure about the SGT) They have said the problem lies with the devices using Broadcomm chips...so yeah

    Use the above code. it seems to work for me will have to check it on a few other devices but yeah

    ReplyDelete
  3. they have said they weren't aware of the problem but have patched and it should be fixed in the latest update for the SGS and other affected products.


    Sorry to disappoint, but...

    I own a Samsung Galaxy S
    GT-I9000
    microcode level 2.3.5
    Baseband version I9000BVJV3
    Kernel 2.6.35.7-I9000BVJVC-CL679241
    Version GINGERBREAD.BVJVC

    I have tried an update yesterday, Jan 29th, 2012 through Kies, it claims my phone is up to date, and reports PDA:JVC/PHONE:JV3/ CSC:JV7 (FTM).

    Yet I still have the problem of the date offset.

    Unless I am missing something, and did not apply the right updates through the right tools?

    ReplyDelete
  4. For clarity, from the settings screen the date and time appear correct, but from the Android SDK version 10, the location listener is showing one day in advance. I gave permission for the Galaxy tab to install an update yesterday thinking it might solve the problem but it had no effect.

    ReplyDelete
  5. I suspect that Samsung were hoping that it was a leap year issue which would just go away after March 1st, 2012.

    Sorry to disappoint - but it hasn't! We have been seeing this problem with the app PhoneTrack installed on Samsung phones since January 1st and it is still there today.

    Hopefully, Samsung will now act responsibly and issue updates for all devices affected by this GPS driver bug.

    ReplyDelete
  6. I hit this bug on my Nexus S running Android 4.0.3 (annoyingly causing a whole bunch of data to be incorrectly timestamped).

    I was upgraded to 4.0.4 yesterday and this seems to have fixed the issue. Not sure if there is a plan to issue fixes to previous Android versions.

    A real howler of a bug though...

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex