Hello it's possible to get location of Pico i.MX7 based on Android Things over Wi-Fi? When I run this code on phone everything works great, but when I run it on Pico, it seems that requestLocationUpdates doesn't update anything and the location is still null. I have permissions in Manifest too(both FINE and COARSE location). Thanks!
public class MainActivity extends Activity {
private LocationManager mLocationManager;
private String locationProvider = LocationManager.NETWORK_PROVIDER;
private TextView lat;
private TextView lon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lat = (TextView) findViewById(R.id.lat);
lon = (TextView) findViewById(R.id.lon);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
2);
}
}
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = mLocationManager.getLastKnownLocation(locationProvider);
mLocationManager.requestLocationUpdates(locationProvider, 10, 0, mLocationListener);
// Toast.makeText(this, "Start", Toast.LENGTH_SHORT).show();
showMyLocation(location);
//Intent intent = new Intent(getApplicationContext(), SprinklerActivity.class);
//startActivity(intent);
}
private void showMyLocation(Location l) {
if (l == null) {
Toast.makeText(this, "No location", Toast.LENGTH_SHORT).show();
lat.setText("0");
lon.setText("0");
} else {
Toast.makeText(this, "Latitude: " + l.getLatitude(), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Longitude: " + l.getLongitude(), Toast.LENGTH_SHORT).show();
lat.setText(l.getLatitude() + "");
lon.setText(l.getLongitude() + "");
}
}
private LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
showMyLocation(location);
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
};