1

i just tryed to set up my first app with Android studio (used eclipser before) and I'm already lost.

Tryed to get signal strength in Button click handler:

            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:

<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>

Error:

FATAL EXCEPTION: main 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: Neither user 10059 nor current process has android.permission.ACCESS_COARSE_LOCATION

rentner323
  • 11
  • 4
  • What version of Android are you testing on? What is the value of `targetSdkVersion` in your `app/build.gradle` file? – CommonsWare Oct 23 '15 at 16:27

1 Answers1

1

If you are targeting API 23 and running in on a device running API 23, you now need to ask the user for approval at runtime as well as having it in your manifest. You will need to check each time if you have permission whenever you try to do something that requires its use, and ask if you do not.

You can check this answer for a list of permissions that you will have to ask for user approval at runtime.

Community
  • 1
  • 1
phxhawke
  • 2,581
  • 23
  • 17