为什么错误无法解析文件'android.permission.ACCESS_FINE_LOCATION'?

时间:2016-11-04 04:48:12

标签: java android android-manifest

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.vave.getbike">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".activity.SignupActivity"
            android:screenOrientation="portrait"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".activity.LoginActivity"
            android:screenOrientation="portrait"
            />
        <activity
            android:name=".activity.RequestRideActivity"
            android:screenOrientation="portrait"
            />
        <activity
            android:name=".activity.LocationActivity"
            android:screenOrientation="portrait"
            />

        <receiver
            android:name=".helpers.SmsBroadcastReceiver"
            android:exported="true">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

执行上述代码时,产生的错误是:

  

无法解析文件android.permission.ACCESS_FINE_LOCATION   检查IntelliLang插件注入的引用。

此错误会导致所有权限。

1 个答案:

答案 0 :(得分:0)

如果您在Marshmallow上测试您的应用程序,请执行以下步骤,否则请忽略。

全局变量

 private static final String[] INITIAL_PERMS = {
            Manifest.permission.ACCESS_FINE_LOCATION};


  private static final int INITIAL_REQUEST = 1337;

  private static final int REQUEST_WRITE_STORAGE = INITIAL_REQUEST + 4;
在Activity onCreate

 if (!canAccessLocation() ) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                requestPermissions(INITIAL_PERMS, INITIAL_REQUEST);
            }
        }

活动内的任何地方

  @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

        switch (requestCode) {

            case REQUEST_WRITE_STORAGE:
                if (canAccessLocation()) {
                    //reload my activity with permission granted or use the features what required the permission
                    System.out.println("permission grantedddd");

                } else {
                    Toast.makeText(this, " Please consider granting it this permission", Toast.LENGTH_LONG).show();
                }
                break;
        }
    }


    private boolean canAccessLocation() {
        return (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION));
    }

    private boolean hasPermission(String perm) {
        return (PackageManager.PERMISSION_GRANTED ==      ContextCompat.checkSelfPermission(this, perm));
    }