Widget Control

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:

Prerequisites

To enable your application to use the widget control functionality:

  1. To use the methods and properties of the Tizen.Applications.WidgetControl class, include the Tizen.Applications namespace in your application:

    using Tizen.Applications;
    
  2. 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 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:

  1. Operate on the control:

    • Get running widget instances:

      IEnumerable<WidgetControl.Instance> instances = control.GetInstances();
      
  2. 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);
      }