How properly ask permission to use Nearby service? - android

This problem appeared only in android 10. I am using Nearby service for iBeacon. In my manifest I'm asking permission ACCESS_FINE_LOCATION and before start nearby service I check if my app has this permission been granted. So why i have this error and how should I properly ask permission to use nearby service? Also i don't like description in asking permission dialog. My app don't use microphone. It frightens users!
Nearby.getMessagesClient(this, new MessagesOptions.Builder()
.setPermissions(NearbyPermissions.BLE)
.build())
.subscribe(getNearbyPendingIntent(), options);

Related

Check if user has granted access to nearby device permission

I am reading the documentation here for the Android Nearby Permission specially for Android 12. I want to check if the user has granted access to Nearby device permission programmatically. The following check is returning true for me all the time
ContextCompat.checkSelfPermission(context,Manifest.permission.BLUETOOTH_CONNECT) ==
PackageManager.PERMISSION_GRANTED
I manually revoked the nearby permission after granting it once in the app and also confirmed by going to the app settings which says nearby permission is not granted. Is there a way to check for this runtime and show the nearby device permission(system dialog) if not granted

Permission regarding Android EMM

I am making an EMM application. This application will only be installed in firm's devices only. Is there any way to grant below permissions programmatically through DevicePolicyManager.
android.permission.SYSTEM_ALERT_WINDOW (Display over other apps)
android.permission.BIND_ACCESSIBILITY_SERVICE (Accessibility service)
android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS (Ignore battery optimization)
I want to grant above permissions through DevicePolicyManager as my app is a system owner app. But, I can't grant them through devicePolicyManager.setPermissionGrantState. As I have also tried devicePolicyManager.setPermittedAccessibilityServices for granting ACCESSIBILY_SERVICE programmatically, but it also didn't work. So, is there is any way I can grant above all permissions programmatically without navigating to that screen and turn in on manually. Or Is there is a way so that user cannot be able to disable the above features anyway. Like when I enable location and other permissions through DevicePolicyManager user is unable to turn it off.
So reviewing: https://developers.google.com/android/work/requirements#4.2.-runtime-permission-grant-state-management_1
and https://developers.google.com/android/management/reference/rest/v1/enterprises.policies#permissionpolicy
seem to indicate at you can create a policy which will automatically grant permissions.
I do see:
PERMISSION_POLICY_AUTO_GRANT
Permission policy to always grant new permission requests for runtime permissions. Already granted or denied permissions are not affected by this.
and
PERMISSION_GRANT_STATE_GRANTED
Runtime permission state: The permission is granted to the app and the user cannot manage the permission through the UI.
which sounds like what you want.

Using USB Manager to automatically grant permission

I am making an app that will allow external devices to be controlled through that app. Every time I plug in a device, I get the popup asking for permission to use the device (even if I already granted it permission to use it and checked the box to remember). Is there a way to just automatically allow all devices and never ask for permission? Or maybe a way to short circuit the permission like
private UsbManager mUsbManager;
mUsbManager.hasPermission(device) = true;
UsbManager doesn't have the method to grant permission, but you can automatically grant permission if you are using intent filters.
An example of what to add in the Android manifest file and the sample device_filter.xml is described here:
https://developer.android.com/guide/topics/connectivity/usb/host.html#using-intents

List Wifi without enabling location service

While developing an app where I scan the WiFi, I found that it does not work if I turn off the location service on my phone. I have provided the app with all the necessary permissions. - ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION.
This is my code:
WifiManager manager= (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
manager.startScan();
In the receiver:
int found = manager.getScanResults().size();
This question answers part of the problem.
Wifi scan results broadcast receiver not working
My questions are:
Is there a way for the app to list the Wifi access points if the location service is turned off?
If location service is absolutely necessary, is there a way for the app to turn on the location service while the app scans the wifi access points?
The only way to get the scanResult without GPS turned on is to set the app's targetSDKversion to 21 or lower.
This will work even on Lolipop and above.
Android 8.0 and Android 8.1:
A successful call to WifiManager.getScanResults() requires any one of the following permissions:
ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
CHANGE_WIFI_STATE
If the calling app does not have any of these permissions, the call fails with a SecurityException.
Android 9 and later:
A successful call to WifiManager.startScan() requires all of the following conditions to be met:
Your app has the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission.
Your app has the CHANGE_WIFI_STATE permission.
Location services are enabled on the device (under Settings > Location).
To successfully call WifiManager.getScanResults() ensure all of the following conditions are met:
Your app has the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission.
Your app has the ACCESS_WIFI_STATE permission.
Location services are enabled on the device (under Settings > Location).
If the calling app doesn't meet all of these requirements, the call fails with a SecurityException.
This is from https://developer.android.com/guide/topics/connectivity/wifi-scan Google Documentation.
Probably they needed the "Location services are enabled on the device" requirement for Android 6.+ because it is the version this permission restrictions first revealed, but they don't seem to had this requirement in documentations since no one has answered this question until now.
Is there a way for the app to list the Wifi access points if the
location service is turned off?
Yes, only system apps can get scan results without the location with the following permission:
android.permission.PEERS_MAC_ADDRESS
permission

SMS Broadcast Receiver just works after resetting permission on android 8 and 6

I've written an app that needs to listen for new SMS. I've used run time permissions for android M and later.
The code works well on android 7.x. But when I want to run it on android 6.x or 8.x, it won't get new SMS until I deny and then grant the SMS permission from settings.
After running app on android 6.x and 8.x, it wants SMS permission and I allow it, but as I said, it wont get new SMS until I open settings, deny permission and then grant that.
Does anyone know what's the problem?
thanks.
I found the answer.
In android 6 and 8, granting READ_SMS permission is not enough. So, you have to use RECEIVE_SMS to get new SMS.

Categories

Resources