public class TileService extends Service
The lifecycle of a TileService is different from some other services in that it may be unbound during parts of its lifecycle. Any of the following lifecycle events can happen indepently in a separate binding/creation of the service.
onTileAdded()
will be called.onStartListening()
and onStopListening()
.onTileRemoved()
will be called.TileService will be detected by tiles that match the "android.service.quicksettings.action.QS_TILE" and require the permission "android.permission.BIND_QUICK_SETTINGS_TILE". The label and icon for the service will be used as the default label and icon for the tile. Here is an example TileService declaration.
<service android:name=".MyQSTileService" android:label="@string/my_default_tile_label" android:icon="@drawable/my_default_icon_label" android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> <intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter> </service>
Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_QS_TILE
Action that identifies a Service as being a TileService.
|
static String |
ACTION_QS_TILE_PREFERENCES
An activity that provides a user interface for adjusting TileService preferences.
|
static String |
ACTION_REQUEST_LISTENING
Used to notify SysUI that Listening has be requested.
|
static String |
EXTRA_COMPONENT |
static String |
EXTRA_SERVICE |
static String |
EXTRA_TOKEN |
static String |
META_DATA_ACTIVE_TILE
Meta-data for tile definition to set a tile into active mode.
|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_ALLOW_WHITELIST_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_CREDENTIAL_PROTECTED_STORAGE, CONTEXT_DEVICE_PROTECTED_STORAGE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, CONTEXTHUB_SERVICE, COUNTRY_DETECTOR, DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, GATEKEEPER_SERVICE, HARDWARE_PROPERTIES_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RADIO_SERVICE, RECOVERY_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SHORTCUT_SERVICE, SIP_SERVICE, SOUND_TRIGGER_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_NAN_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
TileService() |
Modifier and Type | Method and Description |
---|---|
Tile |
getQsTile()
Gets the
Tile for this service. |
boolean |
isLocked()
Checks if the lock screen is showing.
|
boolean |
isSecure()
Checks if the device is in a secure state.
|
IBinder |
onBind(Intent intent)
Return the communication channel to the service.
|
void |
onClick()
Called when the user clicks on this tile.
|
void |
onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
|
void |
onStartListening()
Called when this tile moves into a listening state.
|
void |
onStopListening()
Called when this tile moves out of the listening state.
|
void |
onTileAdded()
Called when the user adds this tile to Quick Settings.
|
void |
onTileRemoved()
Called when the user removes this tile from Quick Settings.
|
static void |
requestListeningState(Context context,
ComponentName component)
Requests that a tile be put in the listening state so it can send an update.
|
void |
setStatusIcon(Icon icon,
String contentDescription)
Sets an icon to be shown in the status bar.
|
void |
showDialog(Dialog dialog)
Used to show a dialog.
|
void |
startActivityAndCollapse(Intent intent)
Start an activity while collapsing the panel.
|
void |
unlockAndRun(Runnable runnable)
Prompts the user to unlock the device before executing the Runnable.
|
attach, dump, getApplication, onConfigurationChanged, onCreate, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, setForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, bindServiceAsUser, canStartActivityForResult, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createCredentialProtectedStorageContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPreferences, getSharedPreferencesPath, getSystemService, getSystemServiceName, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isCredentialProtectedStorage, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastMultiplePermissions, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
bindServiceAsUser, createCredentialEncryptedStorageContext, createDeviceEncryptedStorageContext, getColor, getColorStateList, getDrawable, getSharedPrefsFile, getString, getString, getSystemService, getText, isCredentialEncryptedStorage, isDeviceEncryptedStorage, migrateDatabaseFrom, migrateSharedPreferencesFrom, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public static final String ACTION_QS_TILE_PREFERENCES
public static final String ACTION_QS_TILE
public static final String META_DATA_ACTIVE_TILE
Active mode is for tiles which already listen and keep track of their state in their
own process. These tiles may request to send an update to the System while their process
is alive using requestListeningState(android.content.Context, android.content.ComponentName)
. The System will only bind these tiles
on its own when a click needs to occur.
To make a TileService an active tile, set this meta-data to true on the TileService's
manifest declaration.
<meta-data android:name="android.service.quicksettings.ACTIVE_TILE" android:value="true" />
public static final String ACTION_REQUEST_LISTENING
public static final String EXTRA_SERVICE
public static final String EXTRA_TOKEN
public static final String EXTRA_COMPONENT
public void onDestroy()
Service
public void onTileAdded()
Service.onCreate()
and onStartListening()
, it will only be called when the tile is added
and not on subsequent binds.public void onTileRemoved()
public void onStartListening()
onStopListening()
.getQsTile()
,
Tile.updateTile()
public void onStopListening()
public void onClick()
public final void setStatusIcon(Icon icon, String contentDescription)
The icon will be displayed before all other icons. Can only be called between
onStartListening()
and onStopListening()
. Can only be called by system apps.
icon
- The icon to be displayed, null to hidecontentDescription
- Content description of the icon to be displayedpublic final void showDialog(Dialog dialog)
dialog
- Dialog to show.isLocked()
public final void unlockAndRun(Runnable runnable)
The user will be prompted for their current security method if applicable and if successful, runnable will be executed. The Runnable will not be executed if the user fails to unlock the device or cancels the operation.
public final boolean isSecure()
public final boolean isLocked()
showDialog(android.app.Dialog)
will not present a dialog, as it will
be under the lock screen. If the behavior of the Tile is safe to do while locked,
then the user should use ContextWrapper.startActivity(android.content.Intent)
to launch an activity on top of the lock
screen, otherwise the tile should use unlockAndRun(Runnable)
to give the
user their security challenge.public final void startActivityAndCollapse(Intent intent)
public final Tile getQsTile()
Tile
for this service.
This tile may be used to get or set the current state for this
tile. This tile is only valid for updates between onStartListening()
and onStopListening()
.public IBinder onBind(Intent intent)
Service
IBinder
is usually for a complex interface
that has been described using
aidl.
Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.
onBind
in class Service
intent
- The Intent that was used to bind to this service,
as given to Context.bindService
. Note that any extras that were included with
the Intent at that point will not be seen here.public static final void requestListeningState(Context context, ComponentName component)
META_DATA_ACTIVE_TILE
defined
as true on their TileService Manifest declaration, and will do nothing otherwise.