简体   繁体   中英

Ability to access NFC settings on Android Wear programmatically

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

One hiccup though: while I can easily directly launch into WiFi settings with

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS))

I can't launch into NFC settings with Settings.ACTION_NFC_SETTINGS (the settings app opens but crashes) nor into all Connectivity settings with Settings.ACTION_WIRELESS_SETTINGS (the settings app never opens).

So, how can I programmatically launch directly into the NFC pane of Settings rather than just into the Settings app on my Android Wear 2 watch?

Edit: I've tried the standard way of doing it on Android phones, which is to launch either NFC_SETTINGS or WIRELESS_SETTINGS, but both fail, and I'm looking for info on how to get around that on a watch, so my question is definitely not a duplicate.

I'm open to any solution, from an Accessibility service to an intent to a hidden activity I'm not aware of.

A couple of things to note, to make sure it works.

AndroidManifest.xml should 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 the usage for creating new Intent.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM