【发布时间】:2015-10-23 16:20:47
【问题描述】:
我刚刚尝试使用 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>
错误:
致命异常:主要 10-23 16:01:23.853 12060-12060/de........ E/AndroidRuntime: Process: de........, PID: 12060 10-23 16:01:23.853 12060-12060/de............ E/AndroidRuntime: java.lang.SecurityException: getAllCellInfo: 用户 10059 和当前进程都没有 android.permission.ACCESS_COARSE_LOCATION
【问题讨论】:
-
您在哪个版本的 Android 上进行测试?您的
app/build.gradle文件中targetSdkVersion的值是多少?
标签: android exception permissions