I've declared the following permission on the manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
And per the docs it's a normal permission so no need to request it at runtime on devices running Android M or higher.
The app has crashed but I've tested on multiple devices (with android N) and the app works has expected. Any idea why it has crashed on an emulator with Android SDK built for x86 running android 7.0?
Here is the stacktrace:
Fatal Exception: java.lang.SecurityException: WifiService: Neither user 10076 nor current process has android.permission.ACCESS_WIFI_STATE.
at android.os.Parcel.readException(Parcel.java:1683)
at android.os.Parcel.readException(Parcel.java:1636)
at android.net.wifi.IWifiManager$Stub$Proxy.getWifiEnabledState(IWifiManager.java:1198)
at android.net.wifi.WifiManager.getWifiState(WifiManager.java:1455)
at android.net.wifi.WifiManager.isWifiEnabled(WifiManager.java:1467)
...
To work with WifiManager when scanning the Connections from Android 6.0 it needs to access your location, so that is either the fine location or the coarse location, Add the following to Manifes.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Since Android M (6+) you have to ask the user for permissions during runtime, like iOS-applications for instance.
You can read the docs here, a quick solution is to use a library, e.g EasyPermission or EasyPermission
https://github.com/jineshfrancs/EasyPermission
https://github.com/lalosoft/EasyPermissions
Usage:
easyPermission.requestPermission(this, Manifest.permission.ACCESS_WIFI_STATE);
Related
I need to migrate my application from android 12 to android 13 since in android 12 it does not show any errors, however when testing the app on a device with android 13 it gives me the following error:
[MethodChannelFilePicker] Platform exception:
PlatformException(read_external_storage_denied, User did not allow
reading external storage, null, null).
I've tried adding validations in the manifest, like the ones in:
I have also tried adding these validations in the main:
Add the following permission in your manifest.xml inside
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If it still does not work out, upgrade or change the package you use for picking files and check the documentation.
recommended : https://pub.dev/packages/file_picker/versions/5.2.5
I am trying to show my location on a GoogleMap but Android Studio reports a fatal error on the following line
savedGoogleMap.isMyLocationEnabled = true
The error message is
Missing permissions required by GoogleMap.setMyLocationEnabled: android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION
The problem is the manifest file already includes both permissions so they are not missing!
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Using the IDE context actions to add the permissions inserts additional .ACCESS___LOCATION to the manifest file but Android Studio still reports the fatal error
The apparent issue is Android Studio is ignoring permissions included in the manifest
Earlier posts e.g. here highlight the need for runtime permission checks
My App checks for the required permissions and if checkSelfPermission is not granted I then request the required permissions
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
So at this moment my app shows a fatal error but there appears no way to fix it
Can anyone suggest other avenues I might try ?
Update
Despite the fatal error the App builds and launches? It also shows myLocation on the Google map.
My problem is the manifest file already includes both permissions!
That's not the problem. It is totally fine to have both permissions declared in your AndroidManifest.xml file, just make sure they are added in the correct place like so
After you double checked on that one, make sure you you not only call checkSelfPermission, but also requestPermissions like this:
After receiving the result proceed with your calls (or if the permission was already granted).
If you are positive with this so far and still no success, it would seem to me that something else is causing the problem and I would look into the configuration files, library dependency, caches etc.
I made a music player app. It runs properly in some devices but it crashes in some others. I am not able to understand the error. How do I fix it? All I understand is the first error and that is I have to take separate permission for read phone state permission.
Error 1:
java.lang.RuntimeException: Unable to create service beatbox.neelay.beatbox.MediaService: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2804)
at android.app.ActivityThread.access$1900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1404)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenForSubscriber(ITelephonyRegistry.java:544)
at android.telephony.TelephonyManager.listen(TelephonyManager.java:2514)
at beatbox.neelay.beatbox.MediaService.callStateListener(MediaService.java:612)
at beatbox.neelay.beatbox.MediaService.onCreate(MediaService.java:126)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2794)
... 9 more
This is the error that is submitted by the user.
Error 2:
Writing exception to parcel
java.lang.SecurityException:
External path: /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1481126994678: Neither user 10199 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.
at android.app.ContextImpl.enforce(ContextImpl.java:1443)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1475)
at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:675)
at com.android.providers.media.MediaProvider.enforceCallingOrSelfPermissionAndAppOps(MediaProvider.java:6793)
at com.android.providers.media.MediaProvider.checkAccess(MediaProvider.java:5570)
at com.android.providers.media.MediaProvider.ensureFileExists(MediaProvider.java:4381)
at com.android.providers.media.MediaProvider.getAlbumArtOutputUri(MediaProvider.java:5834)
at com.android.providers.media.MediaProvider.makeThumbInternal(MediaProvider.java:5976)
at com.android.providers.media.MediaProvider.getThumb(MediaProvider.java:5897)
at com.android.providers.media.MediaProvider.openFile(MediaProvider.java:5466)
at android.content.ContentProvider.openAssetFile(ContentProvider.java:1427)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1607)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1673)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:430)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:458)
I have take permission for Android m both in manifest and in Java, and I'm not using any function of write external storage but then also it is showing this error.
On Android >=6.0, We have to request permission runtime.
Step1: add in AndroidManifest.xml file
Step2: Request permission.
Step3: Handle callback when you request permission.
Check this one: Permission at Run Time
Edit: I think you have similar Issue:
you must add this permissions
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to AndroidManifest.xml file
It might be because some of the devices are running Android 6.0 or higher and others are not.
See https://developer.android.com/training/permissions/requesting.html
If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
I made a very, very small demo app reproducing the bug on a Nexus 5 running Android version 6.0.1. The app is on github here: https://github.com/lexi-sr/LayerPermission
I recently added 2 commits in which it targets API 23 and requests permissions at run time, but it still didn't work.
In these 2 commits, it has these settings:
Target SDK: 23
compiles Layer 0.20.3
1) In the commit "Removing layer dependency allows the popup dialog to request the perm…", where it does NOT have layer dependency:
The method ActivityCompat.requestPermissions opens a dialog that requests the Contacts permission, and a log statement within the onRequestPermissionsResult method logs that the permission has been granted.
2) In the commit "Requesting permissions does not work" where it DOES have layer dependency:
ActivityCompat.requestPermissions does not open up any dialogs, but a log statement within onRequestPermissionsResult still prints, logging that it does not have the permission.
It seems like adding the layer dependency is suppressing the ability to request for permissions at run time. Why is this happening?
Luckily, the layer support team was able to help me with this. It solved my problem in the demo app (which targeted SDK 23) and my real app (which targeted SDK 22, to avoid requesting permissions at runtime). After I put tools:node="replace" into my uses-permission line for GET_ACCOUNTS, the pop up dialog was able to appear and grant the permission in the demo app, and the permission was no longer missing in the real app which targeted SDK 22.
Here is the detailed explanation from the Layer support team:
The layer SDK requests the GET_ACCOUNTS permission using a
maxSdkVersion of 18. It would appear that when the manifests get
merged this is overwriting the permission request in your manifest,
thus not requesting that permission for 19+. Could you try appending
tools:node="replace" to the permission in your app's manifest? The
line should read as:
<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="replace" />
See here for the maxSdkVersion documentation:
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
See here for the tools:node documentation:
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers
Peter
We utilize uses-permission-sdk-23 to requests the android.permission.ACCESS_WIFI_STATE permission on devices that are running sdk 23 or higher:
<uses-permission-sdk-23
android:name="android.permission.ACCESS_WIFI_STATE"
android:required="false"/>
The target sdk version of the app is 22 and the code that requires the ACCESS_WIFI_STATE permission is guarded with:
if (Build.VERSION.SDK_INT < 23) {
return;
}
Till now this was working as expected. But currently we observe an increasing number of Security Exceptions:
Caused by java.lang.SecurityException: WifiService: Neither user xxxxx nor current process has android.permission.ACCESS_WIFI_STATE.
The crash affects only ~0.5% of our users on 6.0 and is mostly limited to the following manufacturer/devices combinations:
SONY - Xperia Z5 (Normal/Compact/Premium)
LGE - G3/G4
HTC - One
M8/M9/Desire 816
Is there some general flaw in the described strategy or is this just another case of manufacturer screwed it up and we need another try -> catch -> blame them block?