Das ist also meine MyLocationListener Klassejava.lang.SecurityException „GPS“ Standortanbieter erfordert ACCESS_FINE_LOCATION Erlaubnis
package com.example.gpslocater;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MyLocationListener implements LocationListener {
public TextView mLocationTextView;
Context mContent;
public MyLocationListener(Context context) {
mContent = context;
}
@Override
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();
String Text = "My current location is :" +
"Latitude = " + location.getLatitude() +
" Longitude = " + location.getLongitude();
//figure out a way to make it display through a text view
mLocationTextView.setText(Text);
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(mContent, "Gps Disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(mContent, "Gps Enabled", Toast.LENGTH_SHORT);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Und das ist meine GPS Aktivitätsklasse
public class GPSActivity extends Activity {
private Button mGPSButton;
private TextView mLatitudeTextView;
private TextView mLongitudeTextView;
private LocationManager mLocationManager;
private LocationListener mLocationListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps);
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new MyLocationListener(null);
mGPSButton = (Button)findViewById(R.id.press_button);
mGPSButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.g, menu);
return true;
}
}
Nun, wenn ich es laufen funktioniert es aber nachdem ich die Taste gedrückt habe, reagiert das Programm nicht mehr, es gibt viele Fehlermeldungen
Es ist ein Fehler mich ssage, die sagt, java.lang.SecurityException "gps" location Provider erfordert ACCESS_FINE_LOCATION Erlaubnis, muss ich hinzufügen, wenn ja, wo füge ich es hinzu? Ich denke, das war der Grund für meinen Absturz.
Beachten Sie, dass die Berechtigungen dem Manifestknoten des Manifests hinzugefügt werden müssen. Weitere Informationen zur Berechtigungsstruktur finden Sie hier: [link] (http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms) – GreatSeaSpider