-
Notifications
You must be signed in to change notification settings - Fork 101
Profiles
A Profile is a device state which can be created, modified, or activated for a user based off of an environmental trigger. When you tell the system to create a profile, it will be populated within the system settings application's Profile viewer. This hub can both be controlled by the Settings application and by a 3rd party application.
You must specify the UI information, actions, and optional environmental triggers for a Profile utilizing the methods available within the Profile object. To add your created Profile to the system, invoke a call to ProfileManager.addProfile()
A Profile object must contain the following:
- An identifying name, set by setName()
- A Profile.Type, set by setProfileType()
To use these Profiles API, your application must first declare the write settings permission in AndroidManifest.xml.
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
The snippet below details how to create a Profile object that overrides the devices ring mode settings to be muted.
// Create a new Profile object with a label
Profile profile = new Profile("My New Profile!");
// We're a toggle!
profile.setProfileType(Type.TOGGLE);
// Now create a RingModeSettings object and make set the mode to MUTE with an override of TRUE
RingModeSettings ringSettings = new RingModeSettings(RingModeSettings.RING_MODE_MUTE, true);
profile.setRingMode(ringSettings);
// Add the Profile to the internal service
ProfileManager.getInstance(this).addProfile(profile);
To set the profile to be the primary active profile, you can trigger this by calling setActiveProfile() by passing the UUID of the created Profile object.
UUID profileUuid = profile.getUuid()
ProfileManager.getInstance(this).setActiveProfile(profileUuid);
For further details about the capabilities for the Profiles API, see the javadoc for it.
For the instances where you want to trigger a Profile based off of an environment change as defined by Profile.TriggerType you can set a specific ProfileTrigger on your Profile.
To create a ProfileTrigger you'll need to populate 4 parameters, for something like a trigger based off of a WiFi access point, you can follow the model below:
int triggerType = Profile.TriggerType.WIFI; // This is a wifi trigger
int triggerId = trigger.getSSID(); // Use the AP's SSID as identifier
String triggerName = trigger.getTitle(); // Use the AP's name as the trigger name
int triggerState = Profile.TriggerState.ON_CONNECT; // On Connect of this, trigger
Profile.ProfileTrigger profileTrigger =
new Profile.ProfileTrigger(triggerType, triggerId, triggerState, triggerName);
As you can see we set the TriggerType as WiFI, set the SSID as the triggerId (for tracking), set the title of the access point as the triggerName, and then finally declare that we want to be "triggered" when an ON_CONNECT is given for the access point.
A quick sample of creating a Profile which triggers based off of when you connect to the first available AP can be found here.