我想创建一个应用程序,它会每3秒向scrollview中的textview添加新的经度和纬度。我在手机锁定或应用程序在后台工作时添加新坐标时遇到问题
public class PomiarTrasy extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pomiar_trasy);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
txt1.setText("Szukanie pozycji...");
} else {
txt1.setText("Twój GPS jest wyłączony");
}
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
txt1.setText("Szukanie pozycji...");
else
txt1.setText("Twój GPS jest wyłączony");
}
LocationManager lm;
Location savedLocation = null;
LocationListener locationListener = new LocationListener() {
@SuppressLint("MissingPermission")
@Override
public void onLocationChanged(Location location) {
String latitude = "";
String longitude = "";
if (location != null) {
latitude += location.getLatitude();
longitude += location.getLongitude();
txt1.setText("Uzyskano współrzędne!");
}
btn_start_zapis.setEnabled(true);
if (wlacz == 1) {
txt4.setText(txt4.getText() + "" + location.getLongitude() + ", " + location.getLatitude() + "\n");
txt5.setText(txt2.getText());
txt6.setText(txt3.getText());
txt2.setText(latitude);
txt3.setText(longitude);
}
if (savedLocation == null) {
savedLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
txt1.setText("Szukanie pozycji...");
}
@Override
public void onProviderDisabled(String s) {
txt1.setText("Twój GPS jest wyłączony");
}
};
任何消化我怎么能这样做?我在背景中了解了Service
- GPS工作,但是如何使用TextView
?