Can I access Android HCE application if device is turned off? - android

I'm currently write Android HCE application. And I want to use my HCE application when the device is turned off. I found a way to "Access HCE when Screen off", but no information of power off status.
Is there any way to use HCE application when phone is turned off?

No you can't access because of security reason
One correction also its not accessible if screen is off as mentioned in provided link.
Current Android implementations turn the NFC controller and the application processor off completely when the screen of the device is turned off. HCE services will therefore not work when the screen is off.
It may work on some devices only if vendor implements the OS customized.

Related

How can I monitor the presence of a Danalock, using bluetooth?

I have a Danalock V3 Smart Lock. It's working as advertised, but I want my own Android application to detect whenever I come in-range of this device. So my application needs to be "constantly aware" of whether the device is in-range or not. My question is: is this feasible? If yes, how?
As far as I can tell, the device is not bonded to the phone. If I iterate through the list of bonded devices, it doesn't show:
// example code
for (dev in btAdapter.bondedDevices) {
val string = "${dev.name}: ${dev.address}"
println(string) // <-- All my bonded devices are listed, not the Danalock device
}
The device is managed through Danalocks own proprietary app (as mentioned this is working). But it is a Bluetooth device, so I figured I should be able to detect it's presence in my application, somehow.
This is a bit tricky because theoretically, it should be doable. As Michael Kotzjan said, as long as you know the name of your device (e.g. using nRF Connect), you can continuously scan for this name in the background mode and then as soon as you detect it, you can get a notification in your Android app. The whole BLE beacon technology works like this so it's certainly doable.
Practically, you will be facing a few challenges when it comes to BLE background mode. Since Android P, the OS has an adaptive battery optimisation feature that might kill off some apps in the background. There are a few ways around this but it will not be completely straight-forward. Have a look at the links below which cover the subject in more detail:-
Beacon scanning in background - Android O
Is it possible to share data between Android devices when screen is off
The Ultimate Guide to Android BLE Development (specifically check "Staying connected in the background")
Background scanning on Android 8+
Background BLE scan in doze mode on Android devices

Dim screen but keep NFC working in background

I have an app which connects to smartcards, but when the display turns off, the app disconnects from the smartcard. Is it possible to turn the screen off but keep NFC active so that the app can send data to the smartcard and receive them?
No that's (usually) not possible. On all (most?) Android devices, the NFC stack disables the reader functionality (and puts the NFC chipset into a low-power mode) when the screen turns off. The reason for this is pretty simple: You certainly do not want the NFC reader to drain your battery when you are not using your device (and a mobile device is typically not used when its screen is off). Hence, the only option is to keep the screen on while reading the tag. You can easily do this by adding the FLAG_KEEP_SCREEN_ON to your foreground activity.
This is because the application goes into background. You can try using a service in android to access the card when the application is in background. Be aware that this will consume more battery power.
You can refer this for better understanding

Android TV: turn on / standby screen from application code

I have a Philips Android TV and I'm looking to power on / power off (standby) the TV screen from the code of an Android application.
Is it possible?
Which API allow to activate the screen?
Which API to set the TV back in standby?
I've searched Android API documentation and on internet but I've not found an API for that.
According to Declaring permissions that imply hardware features there is no permission that would enable such a function, and I think it makese sense since a user application should not be able to control an external device screen, that runs in an protected context, different from connected devices such as gamepad, camera, etc.
That said, this does not mean that it's not possibile in any case
What an app can do is to keep the screen device on i.e. not lock the screen while the app is being used that is Keeping the Device Awake.
This is all related to the device policies handled by the DevicePolicyManager i.e. the interface for managing policies enforced on a device.

How can my app find out which NFC mode is enabled?

I've found that Android devices support three NFC modes: reader/writer, P2P, and card emulation.
Is it possible for my app to check which mode is currently enabled?
No, your app can't really check what mode is currently enabled. The point is that, by default, an Android device will periodically check for all three modes (actually it's a bit more complicated than that: those three modes are themselves split into several parts, each polling for a certain technology). So, while the screen is on, you can expect the Android device to cyclically switch between listening for other readers and polling for different types of tag technologies and peer-to-peer mode devices. This is the case regardless of whether you registered to send a message over peer-to-peer mode, an app is registered for HCE, or your app registered for NFC discovery intents. Even if you disable Android Beam in settings, the device will remain to poll for peer-to-peer mode.
Only if you explicitly disable card emulation and P2P using the reader mode API (available on Android 4.4+), your app can control that only reader/writer mode is active (and it can even control which tag technologies should be polled for).
So your app can know what modes it enabled itself and can do some guessing, e.g.
if the screen is on and reader/writer mode was not explicitly forced using the reader mode API, all three modes are likely to be active.
if the screen is off, only card emulation mode may be active (though this is device dependent and HCE is usually not available).

Changing System.Global Settings. Is it possible? - Android

I am little confused about System.Global. According to this document (third point under Important Behavioral Changes) it says that few of the features like turning airplane mode on/off have been include in System.Global in Android 4.2 and higher so its now read only we cannot write it.
Along with airplane mode there is also Bluetooth turn on/off feature included in System.Global which means we shouldn't be able to toggle Bluetooth on/off programmatically since its read only.
But I have some app in my Nexus 7 which runs on version 4.4.2 where the app can easily turn on/off Bluetooth on voice command (one such app is 'Assistant')
How is it possible if the features in System.Global are read only?
Any explanation on this topic will be very much appreciated. Thanks in advance :)
System settings are generally read-only for normal apps. The "Assistant" or "Settings" applications are bundled with the platform and have special permissions. Bluetooth does expose the ability to turn a given "adapter" off and on via the BluetoothAdapter class.
Starting with Android 5.0, it's possible to access some of the settings.
You can use the method setGlobalSetting() in the DevicePolicyManager for that.
However, the caller app must be device owner which is not available to apps deployed on Google Play.
To deploy and activate a device owner, you must perform an NFC data
transfer from a programming app to the device while the device is in
its unprovisioned state. This data transfer sends the same information
as in the provisioning intent described in Managed provisioning.
Source: Android 5.0 APIs

Categories

Resources