Ability to access NFC settings on Android Wear programmatically

I have an Android Wear 2.0 watch (Huawei Watch 2) with NFC. Having NFC in the background, I found it uses a lot of battery, so I made an application that allows me to easily turn it on before using Android Pay and turn it off after.

One hiccup: although I can easily launch WiFi settings right away using

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS))

I can’t run into NFC settings using Settings.ACTION_NFC_SETTINGS(the settings application opens, but it crashes), nor to all the connection settings using Settings.ACTION_WIRELESS_SETTINGS(the settings application never opens).

So, how can I programmatically launch directly in the NFC settings panel, and not just in the Settings application on my Wear 2 Android device?

Edit: I tried the standard way of doing this on Android phones that runs either NFC_SETTINGS or WIRELESS_SETTINGS, but both do not work, and I'm looking for information on how to get around this on the watch, so my question is definitely not duplicated.

I am open to any decision, from accessibility services to the intention of covert activities that I do not know about.

+4
source share
1 answer

A few notes to make sure this works.

AndroidManifest.xml must have permission for NFC settings:

<config-file target="AndroidManifest.xml" parent="/manifest">
    <uses-permission android:name="android.permission.NFC"/>
    <uses-feature android:name="android.hardware.nfc" android:required="true" />
</config-file>

And use to create a new Intent.

Intent i = new Intent("android.settings.NFC_SETTINGS");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
0
source

Source: https://habr.com/ru/post/1681754/


All Articles