As the title says, my app crashes when I want to call requestLocationUpdates. Right now I just want to outpot a Log-Message when the Location is Updated, to see how fast that happens.
MainActivity
private TextView textViewCurrentLocation;
LocationManager mLocationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewCurrentLocation = (TextView) findViewById(R.id.textViewLocation);
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener mlocationListener = new LocationListener() {
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
Log.i("MainActivity", "onLocationChanged");
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
};
// Register the listener with the Location Manager to receive location
// updates
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
mlocationListener);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
mlocationListener);
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.itpro.locationreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
0 comments:
Post a Comment