Android安全异常:清单文件中列出的权限

4

我正在开发的应用程序要求用户在注册过程中共享位置信息。点击“定位我”按钮应该获取GPS坐标(或提供的任何内容,我还不知道)。

当单击按钮时,我收到以下错误消息:

java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

据我所了解,这与在清单文件中列出权限有关,但是该权限已经存在。

我找到的类似问题的线程建议从我测试的设备上卸载应用程序,清除并重新构建项目。我已经执行了所有步骤,但问题仍然存在。我可能还错过了其他一些明显的东西。有什么想法吗?

谢谢!

这是我的 AndroidManifest.xml:

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

    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


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

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

<!-- 
            ATTENTION: This was auto-generated to add Google Play services to your project for
             App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
-->
        <meta-data
            android:name = "com.google.android.gms.version"
            android:value = "@integer/google_play_services_version" />

        <activity
            android:name = ".JoinActivity"
            android:label = "@string/title_activity_join"
            android:theme = "@style/AppTheme.NoActionBar">
        </activity>

        <activity
            android:name = ".LoginActivity"
            android:label = "@string/title_activity_login"
            android:theme = "@style/AppTheme.NoActionBar">
        </activity>

        <activity android:name = ".RegistrationSuccessfulActivity">
            <intent-filter>
                <action android:name = "android.intent.action.VIEW" />

                <category android:name = "android.intent.category.DEFAULT" />
                <category android:name = "android.intent.category.BROWSABLE" />

                <data android:scheme = "http" />
                <data android:scheme = "https" />
                <data android:host = "www.iskillu.com" />
                <data android:host = "iskillu.com" />
            </intent-filter>
        </activity>
        <activity android:name = ".presentation.PresentationActivity">
        </activity>
    </application>
</manifest>

这是执行时抛出异常的方法:

    public void getGpsLocation ( View view )
        {
            LocationManager locationManager = ( LocationManager )        this.getSystemService( Context.LOCATION_SERVICE );

            boolean isProviderEnabled = locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER);

            if ( ! locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER) )
            {
                Toast.makeText ( this.getApplicationContext (), R.string.enable_gps, Toast.LENGTH_LONG ).show () ;
            }
            else
            {
                try {
                    Location myLocation =         locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                    if (myLocation != null)
                    {
                        Log.d("TAG", "Not null");
                    }
                    else
                    {
                        Log.d("TAG", "NULL");
                    }
                }
                catch (SecurityException se) {
                    Log.d("TAG", "SE CAUGHT");
                    se.printStackTrace();
                }
            }
        }

1
可能是重复问题 https://dev59.com/eFwY5IYBdhLWcg3w5bTt - Jay Rathod
请查看此链接(https://dev59.com/eFwY5IYBdhLWcg3w5bTt),它可以帮助您!希望您喜欢。 - Nitesh Pareek
请检查您的目标API是否为23?@丹 - Lips_coder
1个回答

3

3
你应该将这个建议写在评论中。简短的答案并不能证明问题的合理性。 - Jay Rathod
2
但问题仍然没有得到回答;因为这本质上就是答案。 - jaibatrik
问题没有得到解答并不重要。在stackoverflow上有许多可能的重复解决方案可供选择。您可以建议其中的一个解决方案。 - Jay Rathod
这似乎是解决方案。仍然出现异常,但它似乎与之完全无关。现在将问题标记为已解决...谢谢! - Dan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接