public abstract class SettingInjectorService extends Service
SettingInjectorService
must be declared in
the manifest as so:
<service android:name="com.example.android.injector.MyInjectorService" > <intent-filter> <action android:name="android.location.SettingInjectorService" /> </intent-filter> <meta-data android:name="android.location.SettingInjectorService" android:resource="@xml/my_injected_location_setting" /> </service>The resource file specifies the static data for the setting:
<injected-location-setting xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/injected_setting_title" android:icon="@drawable/ic_acme_corp" android:settingsActivity="com.example.android.injector.MySettingActivity" />Here:
Preference.getTitle()
value. The title should make
it clear which apps are affected by the setting, typically by including the name of the
developer. For example, "Acme Corp. ads preferences." Preference.getIcon()
value. Typically this will be a
generic icon for the developer rather than the icon for an individual app.SettingInjectorService
. The activity should use your own branding to help emphasize
to the user that it is not part of the system settings.Application.onCreate()
,
and onGetEnabled()
methods must all be fast. If either is slow,
it can delay the display of settings values for other apps as well. Note further that these
methods are called on your app's UI thread.
For compactness, only one copy of a given setting should be injected. If each account has a
distinct value for the setting, then only settingsActivity
should display the value for
each account.Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_INJECTED_SETTING_CHANGED
Intent action a client should broadcast when the value of one of its injected settings has
changed, so that the setting can be updated in the UI.
|
static String |
ACTION_SERVICE_INTENT
Intent action that must be declared in the manifest for the subclass.
|
static String |
ATTRIBUTES_NAME
Name of the XML tag that includes the attributes for the setting.
|
static String |
ENABLED_KEY
Name of the bundle key for the string specifying whether the setting is currently enabled.
|
static String |
MESSENGER_KEY
Name of the intent key used to specify the messenger
|
static String |
META_DATA_NAME
Name of the meta-data tag used to specify the resource file that includes the settings
attributes.
|
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 |
---|
SettingInjectorService(String name)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
IBinder |
onBind(Intent intent)
Return the communication channel to the service.
|
protected abstract boolean |
onGetEnabled()
Returns the
Preference.isEnabled() value. |
protected abstract String |
onGetSummary()
Deprecated.
not called any more
|
void |
onStart(Intent intent,
int startId) |
int |
onStartCommand(Intent intent,
int flags,
int startId)
Called by the system every time a client explicitly starts the service by calling
Context.startService(android.content.Intent) , providing the arguments it supplied and a
unique integer token representing the start request. |
attach, dump, getApplication, onConfigurationChanged, onCreate, onDestroy, onLowMemory, onRebind, 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_SERVICE_INTENT
public static final String META_DATA_NAME
public static final String ATTRIBUTES_NAME
public static final String ACTION_INJECTED_SETTING_CHANGED
public static final String ENABLED_KEY
public static final String MESSENGER_KEY
public SettingInjectorService(String name)
name
- used to identify your subclass in log messagespublic final 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 final int onStartCommand(Intent intent, int flags, int startId)
Service
Context.startService(android.content.Intent)
, providing the arguments it supplied and a
unique integer token representing the start request. Do not call this method directly.
For backwards compatibility, the default implementation calls
Service.onStart(android.content.Intent, int)
and returns either Service.START_STICKY
or Service.START_STICKY_COMPATIBILITY
.
If you need your application to run on platform versions prior to API
level 5, you can use the following model to handle the older Service.onStart(android.content.Intent, int)
callback in that case. The handleCommand
method is implemented by
you as appropriate:
Note that the system calls this on your
service's main thread. A service's main thread is the same
thread where UI operations take place for Activities running in the
same process. You should always avoid stalling the main
thread's event loop. When doing long-running operations,
network calls, or heavy disk I/O, you should kick off a new
thread, or use AsyncTask
.
onStartCommand
in class Service
intent
- The Intent supplied to Context.startService(android.content.Intent)
,
as given. This may be null if the service is being restarted after
its process has gone away, and it had previously returned anything
except Service.START_STICKY_COMPATIBILITY
.flags
- Additional data about this start request. Currently either
0, Service.START_FLAG_REDELIVERY
, or Service.START_FLAG_RETRY
.startId
- A unique integer representing this specific request to
start. Use with Service.stopSelfResult(int)
.Service.START_CONTINUATION_MASK
bits.Service.stopSelfResult(int)
@Deprecated protected abstract String onGetSummary()
protected abstract boolean onGetEnabled()
Preference.isEnabled()
value. Should not perform
unpredictably-long operations such as network access--see the running-time comments in the
class-level javadoc.
Note that to prevent churn in the settings list, there is no support for dynamically choosing
to hide a setting. Instead you should have this method return false, which will disable the
setting and its link to your setting activity. One reason why you might choose to do this is
if Settings.Secure.LOCATION_MODE
is Settings.Secure.LOCATION_MODE_OFF
.
It is possible that the user may click on the setting before this method returns, so your
settings activity must handle the case where it is invoked even though the setting is
disabled. The simplest approach may be to simply call Activity.finish()
when disabled.Preference.isEnabled()
value