我已經做了一個簡單的應用程序,在用戶的當前位置顯示一個標記,並且我使用了清單中的所有權限。下面是代碼:未授予Android ACCESS_FINE_LOCATION權限或其他內容?
public class LocationActivity extends FragmentActivity implements LocationListener {
SupportMapFragment map;
GoogleMap googleMap;
LocationManager loc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
map=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
onMapReady(googleMap);
//onLocationChanged(location);
}
public void onMapReady(GoogleMap googleMap){
try {
googleMap = map.getMap();
if (googleMap != null) {
googleMap.setMyLocationEnabled(true);
loc = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria crit = new Criteria();
String best = loc.getBestProvider(crit,true);
Location location = loc.getLastKnownLocation(best);
LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude());
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 15));
googleMap.addMarker(new MarkerOptions().title("You're here").position(myLocation));
} else {
Toast.makeText(this, "Fragment has a problem", Toast.LENGTH_SHORT).show();
}
}
catch (Exception e){
Toast.makeText(this,"we can't do it",Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_location, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
//something will go on here
}}
但它顯示了一個運行時錯誤:
ACCESS_FINE_LOCATION is required for PRIORITY_HIGH_LOCATION_REQUEST
什麼是這裏的可能的原因?雖然代碼編譯好,如果我刪除此行 -
googleMap.setMyLocationEnabled(true);
但位置不accurate.` 這裏是清單文件
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="API_Key"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<activity
android:name=".LockScreenActivity"
android:label="@string/title_activity_lock_screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LocationActivity"
android:label="@string/title_activity_location" >
</activity>
</application>
讓我們知道清單snnippet .. plz添加清單片段來解決錯誤 –
添加清單。 PLZ檢查:) –
花花公子將所有權限 外'應用程序'標記 –