用户和当前进程都没有 android.permission.ACCESS_COARSE_LOCATION

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26312733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:15:24  来源:igfitidea点击:

Neither user nor current process has android.permission.ACCESS_COARSE_LOCATION

androidandroid-manifestandroid-permissions

提问by user3290805

I know it may be silly question and I have referred all the similar question before but unfortunately I could resolve this issue. Most probably it is problem in my Manifest.xml file.

我知道这可能是一个愚蠢的问题,我之前已经提到了所有类似的问题,但不幸的是我可以解决这个问题。很可能是我的 Manifest.xml 文件中的问题。

When I am trying to access location, app is crashing

当我尝试访问位置时,应用程序崩溃

here is my manifest.xml

这是我的 manifest.xml

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.tt.test" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".sTest"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>


    </activity>
    <service android:name="com.test.tt.test.sService">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter> </service>
    <service android:name="com.test.tt.test.sServiceRequest" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


</application>

when I run it throw this error

当我运行它时抛出这个错误

 java.lang.SecurityException: Neither user 11029 nor current process has android.permission.ACCESS_COARSE_LOCATION.

Similar with other permissions. I can not see any mistake in my manifest file. Help appreciated

与其他权限类似。我在清单文件中看不到任何错误。帮助表示赞赏

采纳答案by JNI_OnLoad

This means you have some wrong information or malformed info in your menifest file and that is the reason none of your Permission is not identified by your app. Just make sure you have cleaned ANDROIDMANIFEST file with any malformed data.

这意味着您的清单文件中有一些错误的信息或格式错误的信息,这就是您的应用程序无法识别您的所有权限的原因。只需确保您已使用任何格式错误的数据清理了 ANDROIDMANIFEST 文件。

It will work and all permission should be outside Application tag

它会工作,所有权限都应该在应用程序标签之外

回答by sivag1

If you are running on a device on Android Marshmallow and above:

如果您在 Android Marshmallow 及更高版本的设备上运行:

If the device is running Android 6.0 or higher and if the app's target SDK is 23 or higher, the app not just have to list the permissions in the manifest but also must request each dangerous permission it needs while the app is running.

如果设备运行的是 Android 6.0 或更高版本,并且应用程序的目标 SDK 是 23 或更高版本,则应用程序不仅必须在清单中列出权限,而且还必须在应用程序运行时请求它需要的每个危险权限。

More info:

更多信息:

http://developer.android.com/training/permissions/requesting.html

http://developer.android.com/training/permissions/requesting.html

and

http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous

http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous

回答by adev

move the uses-permission outside application just below the manifest tag

将使用权限移到应用程序之外的清单标签下方

回答by user6175333

Moving permission section solved my problem with "Neither user or current process has android.permission.READ_PHONE_STATE". Thank you so much to everyone in this forum. In reference to others, my changes are bellow:

移动权限部分解决了我的问题,“用户或当前进程都没有 android.permission.READ_PHONE_STATE”。非常感谢这个论坛的每一个人。参考其他人,我的变化如下:

Original:

原来的:

    <uses-permission android:name="android.permission.NFC" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />


    <uses-feature
        android:name="android.hardware.nfc"
        android:required="true" />

    <activity android:name=".NfcRead"></activity>
</application>

Change:

改变:

    <uses-permission android:name="android.permission.NFC" />

    <uses-feature
        android:name="android.hardware.nfc"
        android:required="true" />

    <activity android:name=".NfcRead"></activity>
</application>

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

回答by Akki

This exception is related to the runtime permission system in Android 6 and above. The Location permission comes under dangerous permission [check here], so you must have to fulfill below 2 minimum requirements to handle these permissions:

此异常与Android 6 及以上版本的运行时权限系统有关。位置权限属于危险权限 [在这里查看],因此您必须满足以下 2 个最低要求才能处理这些权限:

  1. Declared below 2 permission in manifest (These permissions must be outside application tag)

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />
    
  2. Check for the granted permission at runtime using checkSelfPermission()and request permissions using requestPermissions()if not already granted.

  1. 在清单中声明了以下 2 个权限(这些权限必须在应用程序标签之外)

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />
    
  2. 在运行时使用checkSelfPermission()检查授予的权限,如果尚未授予,则使用requestPermissions()请求权限。

If you have already done both of the above then and still getting error then check below:

如果您已经完成了上述两项操作,但仍然出现错误,请检查以下内容:

  1. You App's targetSdkVersion(should be >=23) [If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed].
  2. Check if you have any thing wrong with you manifest file. You might have malformed manifest file.
  3. Check if you are calling any function, that works on location data, before the user Accept/revoked runtime location permission dialog?
  4. Clean you app (Clean build) and re-run.
  1. 你应用的targetSdkVersion(should be >=23) [如果应用的 targetSdkVersion 设置为小于 23。假设应用尚未使用新的权限系统进行测试,并将切换到相同的旧行为:用户必须接受每个安装时的单一权限,一旦安装,它们将全部被授予]。
  2. 检查您的清单文件是否有任何问题。您可能有格式错误的清单文件。
  3. 在用户接受/撤销运行时位置权限对话框之前,检查您是否正在调用任何处理位置数据的函数?
  4. 清理你的应用程序(清理构建)并重新运行。

Hope this may help :-)

希望这可能会有所帮助:-)