# Titanium.Android.QuickSettingsService

> Android service for creating custom quick settings tiles and handling user's interaction with them.

- Source: https://titaniumsdk.com/docs/sdk/Titanium.Android.QuickSettingsService
- Titanium SDK version: 13.4.1
- Kind: proxy
- Platforms: Android
- Since: Titanium SDK 7.0
- Extends: Titanium.Android.Service
- Inheritance: Titanium.Android.Service > Titanium.Proxy

A special kind of service providing access to a tile in the quick settings menu. Used for customization
and event handling of the tile. Usage is similar to default [Titanium.Android.Service](https://titaniumsdk.com/docs/sdk/Titanium.Android.Service.md) but with the
addition of some specific attributes and methods. This service is not started from within the application 
with the help of an Intent, but instead whenever the custom tile is added in the quick settings menu by the
user. Applications can have multiple tiles in the quick settings menu, but a [Titanium.Android.QuickSettingsService](https://titaniumsdk.com/docs/sdk/Titanium.Android.QuickSettingsService.md)
corresponds to a single one - you need separate service file for every tile.

To create a service file:

  1. Write the JavaScript code you want the service to execute in a separate file.
     The service can execute any Titanium APIs but you should only use non-UI APIs.
  2. Register the service in your `tiapp.xml` file. Refer to the example below.

  Icons used for the 'icon' attribute in the service declaration in tiapp.xml must
  be in the Android drawables folder, so they you should be put under
  `platform/android/res/drawable`
  Icons added with the setIcon method can be outside the directory.

To get a reference to the `Service` inside the JavaScript service code, use the
[Titanium.Android.currentService](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#currentService) property to retrieve a reference to the service,

Further Reading:

  * [Android Quick Settings Tile API](https://developer.android.com/about/versions/nougat/android-7.0.html#tile_api)

## Example: Update Tile Example

This example shows how to create a service in JavaScript.
It will update the Tile in quick settings according to the
user's interaction.

File: updatequicksettings.js:
``` js
var service = Ti.Android.currentService;
service.addEventListener('click', function () {

  if (service.getState() == Ti.Android.TILE_STATE_ACTIVE) {
    service.setState(Ti.Android.TILE_STATE_INACTIVE);
    service.setLabel('Inactive');
    service.setIcon('inactive.png');
  } else {
    service.setState(Ti.Android.TILE_STATE_ACTIVE);
    service.setLabel('Active');
    service.setIcon('active.png');
  }
  service.updateTile();
}
```

Register the service in tiapp.xml:
``` xml
<ti:app>
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <services>
            <service url="updatequicksettings.js" type="quicksettings" label="Active" icon="active.png"/>
        </services>
    </android>
</ti:app>
```

## Properties

### icon

- Type: String | Titanium.Blob | Titanium.Filesystem.File
- Platforms: Android
- Since: Titanium SDK 10.0.0

Changes the Tile's icon.

If no image is passed as Tile icon it will use the Application's one.

### label

- Type: String
- Platforms: Android
- Since: Titanium SDK 10.0.0

The Tile's label.

If no label is set the Tile uses the Application name.

### state

- Type: Number
- Platforms: Android
- Since: Titanium SDK 10.0.0

Sets the state of the Tile.

State can be one of the following: [TILE_STATE_UNAVAILABLE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_UNAVAILABLE),
[TILE_STATE_INACTIVE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_INACTIVE),
[TILE_STATE_ACTIVE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_ACTIVE)

Accepts: `Titanium.Android.TILE_STATE_ACTIVE`, `Titanium.Android.TILE_STATE_INACTIVE`, `Titanium.Android.TILE_STATE_UNAVAILABLE`

## Methods

### getIcon

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [icon](Titanium.Android.QuickSettingsService.icon) property to get/set the value.

Returns the Tile's current icon.

Returns: String | Titanium.Blob | Titanium.Filesystem.File

### getLabel

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [label](Titanium.Android.QuickSettingsService.label) property to get/set the value.

Returns the Tile's current label.

Returns: String

### getState

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [state](Titanium.Android.QuickSettingsService.state) property to get/set the value.

Returns the Tile's current state.

Returns: Number

### isLocked

- Platforms: Android

Returns 'true' if the device is currently locked, 'false' otherwise.

Returns: Boolean

### isSecure

- Platforms: Android

Returns 'true' if the device is in secure state, 'false' otherwise.

Returns: Boolean

### setIcon

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [icon](Titanium.Android.QuickSettingsService.icon) property to get/set the value.

Changes the Tile's icon.

If no image is passed as Tile icon it will use the Application's one.

Parameters:

- `icon` (String | Titanium.Blob | Titanium.Filesystem.File): Source of the icon image

### setLabel

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [label](Titanium.Android.QuickSettingsService.label) property to get/set the value.

Changes the Tile's label.

If no label is set the Tile uses the Application name.

Parameters:

- `label` (String): String to be used.

### setState

- Platforms: Android
- DEPRECATED since 10.0.0. Please use the [state](Titanium.Android.QuickSettingsService.state) property to get/set the value.

Sets the state of the Tile.

State can be one of the following: [TILE_STATE_UNAVAILABLE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_UNAVAILABLE),
[TILE_STATE_INACTIVE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_INACTIVE),
[TILE_STATE_ACTIVE](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#TILE_STATE_ACTIVE)

Parameters:

- `state` (Number): State to be set.

### showDialog

- Platforms: Android

Opens an Alert dialog.

Creates and shows a default Alert dialog with the provided options dictionary.

Note: Alert dialog only supports one of the following: message/options.
If you pass both - only `message` will be shown.

Parameters:

- `options` (showParams): Dictionary containing the options for the dialog.

### startActivityAndCollapse

- Platforms: Android

Collapses the quick settings menu and starts an activity for the passed Intent.

Parameters:

- `intent` (Titanium.Android.Intent): Intent to be fired.

### unlockAndRun

- Platforms: Android

Prompts the user to unlock the device and runs the JS code.

Parameters:

- `jsCode` (String): JavaScript code to be evaluated.

### updateTile

- Platforms: Android

Applies current tile's properties.

Updates the Tile's with it's current label, icon and state.

## Events

### startlistening

- Platforms: Android

Tile is listening for events.

Dispatched whenever the user has opened the quick setting menu and the Tile is added in there.

### stoplistening

- Platforms: Android

Tile has stopped listening for events.

Dispatched whenever the user has collapsed the quick setting menu and the Tile is not visible.

### tileadded

- Platforms: Android

The Tile has been added in the quick menu.

Dispatched whenever the user has moved the Tile for this service in the quick settings menu.

### tiledialogcancelled

- Platforms: Android

Dispatched when the alert dialog has been cancelled.

### tiledialognegative

- Platforms: Android

Dispatched when the negative (index 2) button has been clicked.

### tiledialogneutral

- Platforms: Android

Dispatched when the neutral (index 1) button has been clicked.

### tiledialogoptionselected

- Platforms: Android

An item from the single choice menu has been selected.

Event properties:

- `itemIndex` (Number): Index of the selected item from the single choice menu in the dialog.

### tiledialogpositive

- Platforms: Android

Dispatched when the positive (index 0) button has been clicked.

### tileremoved

- Platforms: Android

The Tile has been removed from the quick menu.

Dispatched whenever the user has removed the Tile for this service from the quick settings menu.

## Inherited members

18 members are inherited. Each is documented on the type that declares it.

- [Titanium.Android.Service](https://titaniumsdk.com/docs/sdk/Titanium.Android.Service.md): `foregroundCancel`, `foregroundNotify`, `intent`, `pause`, `resume`, `serviceInstanceId`, `start`, `start`, `stop`, `stop`, `taskremoved`
- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

