Android工作室权限异常,虽然设置在清单中



我刚试着用Android studio(以前使用过eclipser)设置我的第一个应用程序,我已经迷路了

试图在按钮单击处理程序中获取信号强度:

            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            CellInfoGsm GSM = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
            CellSignalStrengthGsm cellSignalStrengthGsm = GSM.getCellSignalStrength();
            int signalStrength = cellSignalStrengthGsm.getDbm();
            Log.v(TAG, "signalStrength:" + signalStrength);

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.kiel.fh......" >
<uses-permission android:name="android.permission.ACCESS_COARSE_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" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
错误:

FATAL EXCEPTION: main10-23 16:01:23.853 12060-12060/de........E/AndroidRuntime: Process: de........, pid: 1206010-23 16:01:23.853 12060-12060/de............E/AndroidRuntime: java.lang.SecurityException: getAllCellInfo: both user 10059 or current process has android.permission.ACCESS_COARSE_LOCATION

如果你的目标是API 23,并在运行API 23的设备上运行,你现在需要在运行时请求用户批准,以及在你的清单中。每当你尝试做一些需要使用它的事情时,你需要每次检查你是否获得了许可,并询问你是否没有。

您可以检查此答案,以获得在运行时必须请求用户批准的权限列表。

最新更新