java.lang.SecurityException异常" GPS和QUOT;位置提供商要求ACCESS_FINE_LOCATION权限 [英] java.lang.SecurityException "gps" location provider requires ACCESS_FINE_LOCATION permission
问题描述
所以这是我MyLocationListener类
So this is my MyLocationListener Class
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
}
}
这是我的GPS Activity类
And this is my GPS Activity class
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;
}
}
现在,当我运行它,它的工作原理,但我以后preSS按钮,程序停止响应有很多错误信息
Now when I run it it works but after I press the button the program stops responding there are a lot of error messages
有是说java.lang.SecurityException异常GPS定位提供商要求ACCESS_FINE_LOCATION权限的错误信息,我必须补充一点,如果让我在哪里增加吗?我认为这是我的程序崩溃的原因。
There is an error message that says java.lang.SecurityException "gps" location provider requires ACCESS_FINE_LOCATION permission, do I have to add that if so where do I add it? I think that this was the cause of my program to crash.
推荐答案
请从感提供logcat中。
在您的清单中添加此
Make sense from logcat provided. Add this in your manifest
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
这篇关于java.lang.SecurityException异常&QUOT; GPS和QUOT;位置提供商要求ACCESS_FINE_LOCATION权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!