Android的ACCESS_FINE_LOCATION许可不被授予什么? [英] Android ACCESS_FINE_LOCATION permission not being granted or something?

查看:233
本文介绍了Android的ACCESS_FINE_LOCATION许可不被授予什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AI已经做了一个简单的应用程序,在用户的当前位置显示一个标志,我已经使用在清单的所有权限。这里是code:

AI have made a simple app that displays a marker at user's current location and I have used all permissions in the manifest. Here is the code:

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
}}

但它显示了一个运行时错误:

But it shows a runtime error:

ACCESS_FINE_LOCATION需要PRIORITY_HIGH_LOCATION_REQUEST

ACCESS_FINE_LOCATION is required for PRIORITY_HIGH_LOCATION_REQUEST

什么是可能的原因就在这里?虽然code编译好,如果我删除此行 -

What is the probable reason here? Although the code compiles well if I remove this line -

googleMap.setMyLocationEnabled(true);

但是位置不是accurate.`
这里是清单文件

But the location is not accurate.` Here is the manifest file

<?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>

推荐答案

两个问题:


  1. 您所有的&LT;使用许可权&GT; &LT;许可&GT; &LT;使用特征&GT; 元素需要移动的之外&LT的EM>;用途&gt; 。他们应该是根的直接子&LT;表现方式&gt; 元素

  1. All of your <uses-permission>, <permission>, and <uses-feature> elements need to move outside of <application>. They should be immediate children of the root <manifest> element.

您不要使用的android: preFIX的元素名称,如您有 READ_PHONE_STATE READ_EXTERNAL_STORAG​​E 。你不需要 READ_EXTERNAL_STORAG​​E 反正你请求 WRITE_EXTERNAL_STORAG​​E

You do not use the android: prefix on element names, as you have with READ_PHONE_STATE and READ_EXTERNAL_STORAGE. You do not need READ_EXTERNAL_STORAGE anyway, as you are requesting WRITE_EXTERNAL_STORAGE.

这篇关于Android的ACCESS_FINE_LOCATION许可不被授予什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆