Old app can't get WiFi scan results on android N - java

I wrote an app that detects wifi networks and when I press on a network it gives me detailed info about that network. Now the problem is that I wrote it 3 years ago when Android KitKat did not require the popup permission from the user and now when I run it on android N and I press scan it neither scans nor gives me the pop-up permission.
I have not programmed android for a long time and I don't know the changes in Android app coding requirements . Any ideas why this happens?
Current permissions used by the app:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

In order to get WiFi scan results on Marshmallow and later, your app will need to request the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, and the Location Mode setting must be enabled as well.
From the documentation for getScanResults():
the list of access points found in the most recent scan. An app must
hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in
order to get valid results
This change was made due to the fact that location can be determined from WiFi scan results.
As an extra security measure, apps now need to request the Location permission in order to see WiFi scan results, and additionally if the user sets their Location Mode to off, no app can see scan results when running in the background.
So, at a bare minimum, add the ACCESS_COARSE_LOCATION permission to your manifest in order to get WiFi scan results:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
If you keep your target API version lower than 23, you can't request permissions at runtime. In this case, your app will continue to request all permissions at install time.
If you update your app to target API version 23 or later, you will need to request all dangerous permissions at runtime. See here for an example of requesting the Location permission at runtime.

Related

Unable to read device phone numbers despite meeting two of the listed requirements in Android 10 and above

I am trying to use the TelephonyManager class to read the line1Number and the IMEI of the Sim card in the respective slots. I have also tried using TelecomManager class to achieve the same with zero success. I headed over to the official documentation of the c;class on Google documentation and did find out that the methods TelephonyManager.GetLine1Number() or TelephonyManager.GetImei() can only be used if one of the following conditions is met.
If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this is a privileged permission that can only be granted to apps preloaded on the device.
If the calling app is the device owner of a fully-managed device, a profile owner of an organization-owned device, or their delegates (see DevicePolicyManager.getEnrollmentSpecificId()).
If the calling app has been granted the Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER permission.
If the calling app is the default SMS role holder (see RoleManager.isRoleHeld(java.lang.String)).
If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this is a privileged permission that can only be granted to apps preloaded on the device.
I am aware that as from Android 10 accessing device identifiers is kind of technical so because they said if one of the requirements above is met then a method like TelephonyManager.GetImei() should work when invoked. I did try to use a method from an app with device administration privileges like mentioned in the second requirement from the list above, the exception user 10711 does not meet the requirements to read device identifiers is thrown. I also tried the other requirement to declare the permission <uses-permission android:name="android.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER"/> in my manifest and then tried to request for the permission at runtime from the user like below
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.UseIccAuthWithDeviceIdentifier) !=
Permission.Granted)
{
RequestPermissions(new string[]{Manifest.Permission.UseIccAuthWithDeviceIdentifier},682);
}
Meeting that permission requirement also does not make the invocation of the TelephonyManager.GetImei() work. How do I write code that will make devices running Android 10 and above return the IMEI and lineNumber without the exception does not meet the requirements to access device identifiers being thrown?
My manifest file looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="LockScreenAPI.LockScreenAPI">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/>
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER"/>
<application android:allowBackup="true" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme">
</application>
</manifest>
An answer in Android Java is accepted because I use it as the blueprint to implement in a Xamarin Android app, Thank You.

Allow Background Activity for this App in Foreground Service Android

I am running a foreground service in android 10 and 11. But I have issue in my Oppo android 11. Issue is that the execution of any process is stopped after some time because the Allow Background Activity is not enabled for this app in setting. If I allow it then the foreground service works fine. I don't know how to check that if the Allow background activity is enabled or not and how to move to that specific intent. I have search alot but didn't found any solution.
The picture of the app setting is here.
The picture of the app setting is here
The Android Manifest file permissions are here.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Google Play rejects my RN app because of location

I've been facing an issue for a few days now. Everytime I submit my release to Google Play Store, I get a message saying my app has been rejected over and over again. I tried multiple things.
First I tried removing the permissions from my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.lachariottenative">
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
</manifest>
Then I tried editing my app.json file and set permissions to an empty array but each time I get the same error when uploading my app to the Google Play Store. It says that I'm using background location although I am not.
Can you help please?
Thanks in advance
EDIT : I do not wish to use location in my app for the moment. But somehow it still asks for permissions...

Error required permissions android.permission.CONNECTIVITY_INTERNAL android.permission.MAINLINE_NETWORK_STACK

im writing a simple app that want to connect to a specific WiFi Network on Android 10.
I gave all permissions that I thought I might need in the manifest.xml.
<uses-permission-sdk-23 android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission-sdk-23 android:name="android.permission.MAINLINE_NETWORK_STACK" />
But when I use the fuction "connectivitymanager.requestNetwork" I get the Error:
java.lang.SecurityException: Requires one of the following permissions: android.permission.CONNECTIVITY_INTERNAL, android.permission.MAINLINE_NETWORK_STACK.
In the code where I want to request permissions this two permissions are not defined and not available for a request.
Anyone knows about this Permissions or the cause of the error?
Jürgen
I had this issue when I was calling NetworkRequest.Builder#addCapability() and passing in a NetworkCapabilities.TRANSPORT_X value. I needed to call addTransportType() instead.
As per the android docs:
"android.permission.CONNECTIVITY_INTERNAL" : deprecated This permission used to allow too broad access to sensitive methods and all its uses have been replaced by a more appropriate permission. Most uses have been replaced with a NETWORK_STACK or NETWORK_SETTINGS check. Please look up the documentation of the individual functions to figure out what permission now protects the individual function. #SystemApi Allows an internal user to use privileged ConnectivityManager APIs.

Android BLE onScanResult is never called

I have developed a little BLE App for Android which connects with my mobile music Box.
Everything works fine on my phone (Android 9). So I bought a tablet (Android 9) and there onScanResult is never called, but when I search with Android board-function I see the Bluetooth device.
ACCESS_FINE_LOCATION
BLUETOOTH
BLUETOOTH_ADMIN
is set and Location is set to on.
if your bluetooth is on then give runtime permission of , ACCESS_FINE_LOCATION and ACCESS_CORSE_LOCATION and still you are facing this issue then gps on and restart scanning its working fine.
Required permission for BLE,
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and check gps is enable or not
private fun enableLocation(): Boolean {
val service = activity?.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER)
return enabled
}
and if return false then
val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
startActivity(intent)
for enable your gps progrmatically and if true then scan your device.
ACCESS_FINE_LOCATION could be declared in manifest but it's not treated as granted by default. Have you requested for granting this permission in runtime? If not, request for it in runtime or just go to permissions section in your app settings and grant it manually.

Categories

Resources