Enable/Disable NFC with ADB command - android

Is there any way to disable/enable NFC via ADB shell commands?
I found one answer here.
What I tried from the above link:
# Enable NFC
service call nfc 5
# Disable NFC
service call nfc 4
but it's not working.
Any help appreciated. Thanks.

I don't know why no one has posted this already
svc nfc <enable|disable>
Works perfectly
Edit: Requires > Android 6.0

# Disable NFC
service call nfc 7
Verified for Android 8.0
Cheers!

In your DDMS of eclipse or using logfilter or any runtime log capturing tool, you need to get the process ID of your NFCService. Then you can kill or stop that process by giving the process ID.

System services' method codes may vary with Android versions. Therefore, before making a service's method call browse the AOSP sources.
Below is a summary of the NFC's enable/disable calls up to Android 5.1.1. Also keep in mind that (in the sources)
int FIRST_CALL_TRANSACTION = 0x00000001
,i.e. equals to 1.
Android 4.4 - Android 5.1.1:
# Disable NFC
service call nfc 5
# Enable NFC
service call nfc 6
Android 4.0.1 - Android 4.3.1:
# Disable NFC
service call nfc 4
# Enable NFC
service call nfc 5
Android 2.3.4 - Android 2.3.7:
# Disable NFC
service call nfc 18
# Enable NFC
service call nfc 19
Android 2.3.3:
# Disable NFC
service call nfc 20
# Enable NFC
service call nfc 21
Android 2.3.2:
# Disable NFC
service call nfc 13
# Enable NFC
service call nfc 14
To check the status of the NFC service use the dumpsys command:
dumpsys nfc

Please try this
# Enable NFC
service call nfc 6
# Disable NFC
service call nfc 5
please check here in slide no 32

For Android Version > 7, please use following -
# Enable NFC
service call nfc 7
# Disable NFC
service call nfc 6
Verified on 7.1.1... Should work for atleast 7.x

Related

Android 7.0 init.rc mediaserver

I have question about Android 7.0 boot sequence.
In Android 6.0, the init process will parse the init.rc and initiate the mediaserver:
service media /system/bin/mediaserver
class main
user main
group audio camera inet net_bt net_bt_admin net_bw_acct drmrpc mediadrm qcom_diag radio cw_access
...
But in Android 7.0, the init.rc doesn't have the above code, so i wondering who is the one initiate the mediaserver?? could be systemserver or not?
Try to find a file named mediaserver.rc in frameworks/native. Android 7.0 tryes to separate the init.rc actions and services according to reason. And you'll find them in system/etc/init/ on the device.

hidraw set-report/send-report doesn't work with Android 6.x

I have a bluetooth hid device that I need to communicate with. Target platform is Android 5.x+. Currently testing on Nexus 7 2013 tablet.
My code works fine on android 5.x, I am able to receive, send and set reports on Android 5.x.
On Android 6.x, I am only able to receive reports sent by device, but I am not able to send or set reports. It looks like my set/send report requests are silently ignored by HID/BT stack.
The code that talks to /dev/hidraw* nodes runs as a native daemon as root.
Are there any new requirements to be able to set/send reports to Bluetooth hid devices on Android 6.x? Is there any changes I could make to AOSP to allow this to work?
[Update]
Logcat says:
05-17 11:22:56.085 2455-4061/com.android.bluetooth E/bt_btif: uhid_event: Invalid size read from uhid-dev: 4108 != 4
I do not understand how reading from uhid will return only 4 bytes! First 4 bytes are supposed to contain only the type of event. Is there any scenario that will result in a read() of less than sizeof(struct uhid_event) bytes?
Could this indicate a bug in uhid driver?
I checked available kernel sources and found that hidraw driver does not contain usable source to feed reports to /dev/hidraw* nodes
I also found that Bluedroid correctly receives and sends reports internally.
Simplest method to get/set/send reports I found was to modify bluedroid to communicate directly with my App for vendor-specific reports. I integrated my daemon into Bluedroid directly.

android using GSMPhone to communicate with rild

I'm working on a non phone device that run Android 2.3.3. We have a custom Android version (with some additionnal driver) and my application has "system" privileges since we build our apps with the same key used to build android.
I had unlocked full Android API (including com.android.internal.*) following this post : https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/.
I deleted the Phone.apk from the device to ensure that no process is using rild.
I can instanciate a GSMPhone from my app, but after, I'm unable to execute any commands like supplyPin or getImei. I always have the same error : 
CommandException: RADIO_NOT_AVAILABLE.
I'm really stuck here, any help would be precious.
CommandException: RADIO_NOT_AVAILABLE indicates that the rild socket is not opened. In other words, the rild service is not attached to the underlying basebane/modem you are using.
Run ps in adb shell to check if rild service is in the list. If it is in the list, run ls -l /dev/tty* and check if the modem device attached with the Android platform exists here or not. If it does not exist, it means that the Kernel is unable to enumerate your modem device and you need to add support in kernel for it. If it exists, run adb logcat -b radio and check the radio logs output which would really be helpful to diagnose the issue further.
adb shell ps | grep rild to check if RILD is in runing.
Since you can access all the api, do some initialization like PhoneApp do in Phone application OnCreate(mostly like setting params to modem, set radio power which will power on/off the modem, etc)

Run google-chrome with flags on Android

There are command line flags (or "switches") that Chromium (and Chrome) accept in order to enable particular features or modify otherwise default functionality.
Chromium Command Line Switches
Run Chromium with flags
Tried Chrome 41.0.xx and Chromium 43.0.xxx shell with:
# echo "chrome <flags>" > /data/local/tmp/android-webview-command-line
# echo "chrome <flags>" > /data/local/tmp/content-shell-command-line
Any idea how to run chrome with flags on Android or directly add these into default profile.
Want to add --sync-url flag to use my sync server instead of google sync servers. chrome://flags only enable/disable flags but wont let you add new flag.
New method added in Chrome 661 that works for a production build on unrooted devices.
Using adb, write the flags to /data/local/tmp/chrome-command-line.
For example:
~$ adb shell 'echo --unsafely-treat-insecure-origin-as-secure=http://a.test > /data/local/tmp/chrome-command-line'
In chrome://flags, turn on enable-command-line-on-non-rooted-devices.
Force stop Chrome (the relaunch now button will not trigger the reading of the flags file, even though the danger snackbar will disagree).
Verify in chrome://version that this worked.
https://www.chromium.org/developers/how-tos/run-chromium-with-flags#TOC-Android
What you're doing is correct, but seems like you're writing the switches to the wrong file for Chrome (and note that the file that you write the switches to may vary based on the OS version [or maybe phone?] ).
I tried this on two different phones, and had to write to two different files! Hopefully one of them will work for you:
Phone 1: Nexus 6 with Android 6.0.1
Simply do the following in adb shell:
echo "chrome --sync-url" > /data/local/tmp/chrome-command-line'
Phone 2: MotoG with Android 4.4.4
This is a bit trickier. It turned out that Chrome actually reads the switches from /data/local/chrome-command-line (not in the tmp subdirectory!). Now the issue is that on an unrooted phone you won't have permission to write to this file! So I had to root my phone* and use su to write to the file:
adb shell
su
echo "chrome --sync-url" > /data/local/chrome-command-line
*Rooting an Android phone is actually very easy and takes only a few minutes. There are a number of one click apps for rooting your phone (e.g. KingoRoot). For the case of MotoG, I had to do a few more steps to root, following this)
I needed insecure origin flag for testing of service workers on mobile device. However, for some reason these flags did not work on mobile chrome. Behaviour similar to insecure origin flag can be achieved by port forwarding.
You can find further info in my original answer here: https://stackoverflow.com/a/56146180/5048121
This does not apply exclusively on service workers, if you need https behavior on mobile device, you can combine it for example with allow-insecure-localhost flag or use self-signed certificate for localhost on server and get rid of cert errors on mobile chrome.
You need chromium debug build in order to use these switches.

unable to run my nfc application

I m creating a sample Nfc application.. in GingerBread2.3.3 - which includes nfc features.. i have checked for the Nfc service running on the system bootup... the service runs perfectly on boot up...
I m using an external hardware to detect the Nfc tags... the hardware is fine... checked it also...
From my application, i have set permission for Nfc and I have included the Nfc feature also..
I found out that NfcAdapter.java - hasSystemFeature() is returning false for Nfc... but my Nfc service is running.... In settings, I don't get any Nfc related features.. On setting this hasSystemFeature() to return true. I get the Nfc settings. But my application does nothing..
I checked in current.xml whether it includes nfc features.. and it also has Nfc features..
Now I m struck not sure what to do.. Pls do help me out with this...

Categories

Resources