|
8 | 8 | [](https://sonarcloud.io/summary/new_code?id=pcolby_nfc-quick-settings)
|
9 | 9 | [](https://sonarcloud.io/summary/new_code?id=pcolby_nfc-quick-settings)
|
10 | 10 |
|
11 |
| -NFC Quick Settings is a really basic Android app with no GUI of it's own, that simply adds an NFC |
12 |
| -tile to the tiles available to the [Quick Settings panel][]. |
| 11 | +NFC Quick Settings is a really basic Android app with no GUI of it's own, that simply adds an NFC tile to the tiles |
| 12 | +available to the [Quick Settings panel][]. |
13 | 13 |
|
14 |
| -*Screenshots go here...* |
| 14 | +The Quick Settings tile indicates the current NFC status (enabled, or disabled), but the action it takes when tapped |
| 15 | +varies a little depending on the permissions available. See [Basic](#basic-mode) and [Advanced](#advanced-mode) modes |
| 16 | +below. |
15 | 17 |
|
16 |
| -## Internal Details |
| 18 | +[](https://play.google.com/store/apps/details?id=au.id.colby.nfcquicksettings)  |
| 19 | +[](https://f-droid.org/packages/au.id.colby.nfcquicksettings) |
17 | 20 |
|
18 |
| -Just for the curious, the application implements a basic [TileService][], that overrides: |
| 21 | +## Basic Mode |
19 | 22 |
|
20 |
| -* [onStartListening()][] to check the default NFC adapter's current status, and update the tile state |
21 |
| - accordingly; and |
22 |
| -* [onClick()][] to show the device's NFC Settings by starting the [NFC Settings][] activity. |
| 23 | +In the _basic_ mode, which requires no special permissions, tapping the tile will simply open the device's NFC Settings |
| 24 | +page (assuming the device has one). This is actually the best that can be done using official Android APIs. |
23 | 25 |
|
24 |
| -[NFC Settings]: https://developer.android.com/reference/android/provider/Settings#ACTION_NFC_SETTINGS |
25 |
| -[onClick()]: https://developer.android.com/reference/android/service/quicksettings/TileService#onClick() |
26 |
| -[onStartListening()]: https://developer.android.com/reference/android/service/quicksettings/TileService#onStartListening() |
27 |
| -[Quick Settings panel]: https://support.google.com/android/answer/9083864 |
28 |
| -[TileService]: https://developer.android.com/reference/android/service/quicksettings/TileService |
| 26 | +## Advanced Mode |
| 27 | + |
| 28 | +The advanced mode requires special permissions (see below), but once enabled, tapping the NFC Quick Settings tile will |
| 29 | +turn the NFC service on or off directly, without having to open the NFC settings page at all. Unfortunately, to acheive |
| 30 | +this _advanced_ mode, NFC Quick Settings needs to use APIs not intended for third-party applications (specifically |
| 31 | +[`NfcAdapter::enable()`][] and [`NfcAdapter::disable()`][]), and to use those methods the tile needs the special |
| 32 | +[`WRITE_SECURE_SETTINGS`][] permission. |
| 33 | + |
| 34 | +### Granting `WRITE_SECURE_SETTINGS` Permission |
| 35 | + |
| 36 | +As the [`WRITE_SECURE_SETTINGS`][] permission is not intended to be used by third-party applications, it needs to be |
| 37 | +granted via the [Android Debug Bridge (adb)][] tool. |
| 38 | + |
| 39 | +1. Install [Android Debug Bridge (adb)][]: |
| 40 | + |
| 41 | + > `adb` is included in the Android SDK Platform Tools package. Download this package with the [SDK Manager][], which |
| 42 | + > installs it at `android_sdk/platform-tools/`. If you want the standalone Android SDK Platform Tools package, |
| 43 | + > [download it here](https://developer.android.com/tools/releases/platform-tools). |
| 44 | +
|
| 45 | +2. Install NFC Quick Settings, via [Google Play] or [GitHub Releases]. |
| 46 | + |
| 47 | +3. [Enable adb debugging on your device](https://developer.android.com/tools/adb#Enabling). |
| 48 | + |
| 49 | +4. [Connect your device via Wi-Fi](https://developer.android.com/tools/adb#connect-to-a-device-over-wi-fi). |
| 50 | + |
| 51 | +5. Grant the permission to NFC Quick Settings via `adb`: |
| 52 | + |
| 53 | + ```sh |
| 54 | + adb shell pm grant au.id.colby.nfcquicksettings android.permission.WRITE_SECURE_SETTINGS |
| 55 | + ``` |
| 56 | + |
| 57 | +If for some reason you want to revoke the [`WRITE_SECURE_SETTINGS`][] permission, and restore the _basic_ mode, then |
| 58 | +simply follow the same steps as above, but replace `grant` with `revoke`. That is, run: |
| 59 | + |
| 60 | +```sh |
| 61 | +adb shell pm revoke au.id.colby.nfcquicksettings android.permission.WRITE_SECURE_SETTINGS |
| 62 | +``` |
| 63 | + |
| 64 | +[`NfcAdapter::disable()`]: https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/nfc/NfcAdapter.java;l=986?q=NfcAdapter "android.nfc.NfcAdapter::disable()" |
| 65 | +[`NfcAdapter::enable()`]: https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/nfc/NfcAdapter.java;l=947?q=NfcAdapter "android.nfc.NfcAdapter::enable()" |
| 66 | +[`WRITE_SECURE_SETTINGS`]: https://developer.android.com/reference/android/Manifest.permission#WRITE_SECURE_SETTINGS "android.permission.WRITE_SECURE_SETTINGS" |
| 67 | +[Android Debug Bridge (adb)]: https://developer.android.com/tools/adb "Android Debug Bridge (adb)" |
| 68 | +[GitHub Releases]: https://github.com/pcolby/nfc-quick-settings/releases "NFC Quick Settings releases" |
| 69 | +[Google Play]: https://play.google.com/store/apps/details?id=au.id.colby.nfcquicksettings "NFC Quick Settings on Google Play" |
| 70 | +[SDK Manager]: https://developer.android.com/studio/intro/update#sdk-manager "Update your tools with the SDK Manager" |
| 71 | +[Quick Settings panel]: https://support.google.com/android/answer/9083864 "Change settings quickly on your Android phone" |
0 commit comments