Widget Control
PUBLISHED
The widget control provides information about installing and running widget applications.
It also provides functions for the following:
- Sending update requests to the widget applications
- Retrieving details of running instance for the same package widget applications
The main features of the Tizen.Applications.WidgetControl
class include:
- Creating a widget control
For using the widget control features, you can create widget control instance with specific widget ID.
- Getting information on widget applications
For the widget applications that is installed but not running, you can retrieve widget information.
- Listening widget lifecycle events on widget applications
For running widget applications, you can listen widget application lifecycle events.
- Communicating with running widget instances
For running widget instances, you can trigger an update event, send update data, and retrieve running widget instances detail.
Prerequisites
To enable your application to use the widget control functionality:
- To use the methods and properties of the Tizen.Applications.WidgetControl [1] class, include the Tizen.Applications [2] namespace in your application:
using Tizen.Applications;
- To get information on widget application, the application has to request permission by adding the following privilege to the
tizen-manifest.xml
file:
<privileges> <privilege>http://tizen.org/privilege/widget.viewer</privilege> </privileges>
Creating a widget control
Create an instance of widget control with an ID of the widget application using the Tizen.Applications.WidgetControl [1] class:
WidgetControl control = new WidgetControl(Your Widget ID);
Getting Information on Widget Applications
Get the main application ID, package ID, and available scale lists from the control:
string mainId = control.MainAppId; string packageId = control.PackageId; IEnumerable<WidgetControl.Scale> scales = control.GetScales();
Listening Widget Lifecycle Events on Widget Applications
Add lifecycle listeners on the control to listen to the widget lifecycle events:
private static void OnCreated(object sender, Tizen.Applications.WidgetLifecycleEventArgs args) { string instanceId = args.InstanceId; string widgetId = args.WidgetId; /// Widget application is created } private static void OnDestroyed(object sender, Tizen.Applications.WidgetLifecycleEventArgs args) { /// Widget application is destroyed } private static void OnPaused(object sender, Tizen.Applications.WidgetLifecycleEventArgs args) { /// Widget application is paused } private static void OnResumed(object sender, Tizen.Applications.WidgetLifecycleEventArgs args) { /// Widget application is resumed } control.Created += OnCreated; control.Created += OnDestroyed; control.Created += OnPaused; control.Created += OnResumed; string mainId = control.MainAppId; string packageId = control.PackageId; IEnumerable<WidgetControl.Scale> scales = control.GetScales();
Communicating with Running Widget Instances
To communicate with the running widget instances, follow these steps:
- Operate on the control:
- Get running widget instances:
IEnumerable<WidgetControl.Instance> instances = control.GetInstances();
- Get running widget instances:
- Operate on the instances:
- Get details of running widget instances and send an update to widget application:
foreach (WidgetControl.Instance ins in instances) { /// Get widget instance content var data = ins.GetContent(); /// Change widget update period ins.ChangePeriod(2.0); /// Trigger widget update ins.ChangeContent(data, true); }
- Get details of running widget instances and send an update to widget application: