Most visited

Recently visited

Added in API level 19

SettingInjectorService

public abstract class SettingInjectorService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.location.SettingInjectorService


Dynamically specifies the enabled status of a preference injected into the list of app settings displayed by the system settings app

For use only by apps that are included in the system image, for preferences that affect multiple apps. Location settings that apply only to one app should be shown within that app, rather than in the system settings.

To add a preference to the list, a subclass of 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: To ensure a good user experience, your 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.

Summary

Constants

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.

String ACTION_SERVICE_INTENT

Intent action that must be declared in the manifest for the subclass.

String ATTRIBUTES_NAME

Name of the XML tag that includes the attributes for the setting.

String META_DATA_NAME

Name of the meta-data tag used to specify the resource file that includes the settings attributes.

Inherited constants

From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2

Public constructors

SettingInjectorService(String name)

Constructor.

Public methods

final IBinder onBind(Intent intent)

Return the communication channel to the service.

final void onStart(Intent intent, int startId)

This method is deprecated. Implement onStartCommand(Intent, int, int) instead.

final int onStartCommand(Intent intent, int flags, int startId)

Called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.

Protected methods

abstract boolean onGetEnabled()

Returns the isEnabled() value.

abstract String onGetSummary()

This method was deprecated in API level 21. not called any more

Inherited methods

From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

ACTION_INJECTED_SETTING_CHANGED

Added in API level 19
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.

Constant Value: "android.location.InjectedSettingChanged"

ACTION_SERVICE_INTENT

Added in API level 19
String ACTION_SERVICE_INTENT

Intent action that must be declared in the manifest for the subclass. Used to start the service to read the dynamic status for the setting.

Constant Value: "android.location.SettingInjectorService"

ATTRIBUTES_NAME

Added in API level 19
String ATTRIBUTES_NAME

Name of the XML tag that includes the attributes for the setting.

Constant Value: "injected-location-setting"

META_DATA_NAME

Added in API level 19
String META_DATA_NAME

Name of the meta-data tag used to specify the resource file that includes the settings attributes.

Constant Value: "android.location.SettingInjectorService"

Public constructors

SettingInjectorService

Added in API level 19
SettingInjectorService (String name)

Constructor.

Parameters
name String: used to identify your subclass in log messages

Public methods

onBind

Added in API level 19
IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned 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.

Parameters
intent 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.
Returns
IBinder Return an IBinder through which clients can call on to the service.

onStart

Added in API level 19
void onStart (Intent intent, 
                int startId)

This method is deprecated.
Implement onStartCommand(Intent, int, int) instead.

Parameters
intent Intent
startId int

onStartCommand

Added in API level 19
int onStartCommand (Intent intent, 
                int flags, 
                int startId)

Called by the system every time a client explicitly starts the service by calling startService(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 onStart(Intent, int) and returns either START_STICKY or 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 onStart(Intent, int) callback in that case. The handleCommand method is implemented by you as appropriate:

// This is the old onStart method that will be called on the pre-2.0
// platform.  On 2.0 or later we override onStartCommand() so this
// method will not be called.
@Override
public void onStart(Intent intent, int startId) {
    handleCommand(intent);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

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.

Parameters
intent Intent: The Intent supplied to startService(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 START_STICKY_COMPATIBILITY.
flags int: Additional data about this start request. Currently either 0, START_FLAG_REDELIVERY, or START_FLAG_RETRY.
startId int: A unique integer representing this specific request to start. Use with stopSelfResult(int).
Returns
int The return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the START_CONTINUATION_MASK bits.

Protected methods

onGetEnabled

Added in API level 19
boolean onGetEnabled ()

Returns the 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 LOCATION_MODE is 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 finish() when disabled.

Returns
boolean the isEnabled() value

onGetSummary

Added in API level 19
String onGetSummary ()

This method was deprecated in API level 21.
not called any more

This method is no longer called, because status values are no longer shown for any injected setting.

Returns
String ignored

Hooray!