Está en la página 1de 21

Trng i hc Bch Khoa H Ni

Hanoi University of Science and Technology

Tizen Development
Application
Hanoi University of Science and
Technology
Hoang Van Hiep
hiephv@soict.hust.edu.vn

HUST 2015

Application Framework
n
n
n
n

Application fundamentals
Badges
Bundles
Data Controls

STP@2015

Application Framework
n

Application fundamentals:
Start or exit the main event loop
n Register callbacks for application states
change events
n Register callbacks for basic system events
n Get information about the application
n

STP@2015

Start/Exit the main event loop


n

Start Main event loop

ui_app_main (int argc, char **argv, ui_app_lifecycle_callback_s


*callback, void *user_data)
n

Exit Main event loop

ui_app_exit (void)

STP@2015

Register callbacks for app states

STP@2015

Register callbacks for system events

STP@2015

Get information about application


n
n

Get current orientation of device


Get the internal and external shared
folders

STP@2015

Application states change

STP@2015

Main event loop

STP@2015

Launching Applications
n

An application can be launched from the


launcher or from another application.
Two methods to launch an application
Explicit launch: launch an application with
application id
n Implicit launch: launch an application with an
operation, URI, or MIME type.
n

STP@2015

10

Explicit launch an application


#include <app.h>
#include <dlog.h>
#define TAG "MY_TAG
app_control_h app_control;
app_control_create(&app_control);
app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
app_control_set_app_id(app_control, "org.tizen.calculator");
if (app_control_send_launch_request(app_control, NULL, NULL) ==
APP_CONTROL_ERROR_NONE)
{
dlog_print(DLOG_INFO, TAG, "Succeeded to launch a calculator app.");
}
else
{
dlog_print(DLOG_ERROR, TAG, "Failed to launch a calculator app.");
}
app_control_destroy(app_control);
STP@2015

11

Explicit launch an application


n

Exercise
Create a new application that has a button
(named Launch an application)
n When user clicks on the button launch
another application (E.g., launch the Hello
World application)
n

STP@2015

12

Explicit launch an application


n

Exercise
n
n
n

Does your app run properly?


Could you call another app from your app?
What error code did you get?

STP@2015

13

To launch an application
n

In the Caller Application


n

Declare the launch privilege

<privilege>http://tizen.org/privilege/appmanager.launch</privilege>

In the Callee (Target) Application


n
n

Declare the launch privilege


<privilege>http://tizen.org/privilege/appmanager.launch</
privilege>

Export the app control operation


n

Example:

<operation name="http://tizen.org/appcontrol/operation/view"/>

STP@2015

14

Implicit launch an application


n

Only 3 data categories are used to determine


which application can be launched:
Operation, URI, and MIME type
The application launcher framework scans
the installed applications to find applications
where 3 categories are exactly matched.
If only 1 application is matched with 3 categories
It will be launched
n If more than 1 matched application are found
the application selector are showed.
n

STP@2015

15

Implicit launch an application


#include <app.h>
#include <dlog.h>
#define TAG "MY_TAG"
app_control_h app_control;
app_control_create(&app_control);
app_control_set_operation(app_control,
APP_CONTROL_OPERATION_CREATE_CONTENT);
app_control_set_mime(app_control, "image/jpg");
if (app_control_send_launch_request(app_control, NULL, NULL) ==
APP_CONTROL_ERROR_NONE)
{
dlog_print(DLOG_INFO, TAG, "Succeeded to launch a viewer app.");
}
else
{
dlog_print(DLOG_ERROR, TAG, "Failed to launch a viewer app.");
}
STP@2015
app_control_destroy(app_control);

16

Implicit launch an application


#include <app.h>
#include <dlog.h>
#define TAG "MY_TAG
app_control_h app_control;
app_control_create(&app_control);
app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
app_control_set_uri(app_control, "file:///home/myhome/Photos/1_photo.jpg");
app_control_set_mime(app_control, "image/*");
if (app_control_send_launch_request(app_control, NULL, NULL) ==
APP_CONTROL_ERROR_NONE)
{
dlog_print(DLOG_INFO, TAG, "Succeeded to launch a viewer app.");
}
else
{
dlog_print(DLOG_ERROR, TAG, "Failed to launch a viewer app.");
}
STP@2015
app_control_destroy(app_control);

17

Implicit launch an application


#include <app.h>
#include <dlog.h>
#define TAG "MY_TAG"
app_control_h app_control;
app_control_create(&app_control);
app_control_set_operation(app_control,
APP_CONTROL_OPERATION_CREATE_CONTENT);
app_control_set_mime(app_control, "text/plain");
if (app_control_send_launch_request(app_control, app_control_result, NULL) ==
APP_CONTROL_ERROR_NONE)
{
dlog_print(DLOG_INFO, TAG, "Succeeded: the application is launched.");
}
else
{
dlog_print(DLOG_ERROR, TAG, "Failed to launch an application.");
}
STP@2015
app_control_destroy(app_control);

18

Implicit
launch
an
application
static void app_control(app_control_h app_control, void* user_data)
{

struct appdata *ad = (struct appdata *)user_data;


char *operation, *mime, *app_id;
app_control_h reply;
app_control_get_operation(app_control, &operation);
if (!strcmp(operation, APP_CONTROL_OPERATION_CREATE_CONTENT))
{
app_control_get_mime(app_control, &mime);
if (!strcmp(mime, "text/plain"))
{
app_control_create(&reply);
app_get_app_id(&app_id);
app_control_add_extra_data(reply, APP_CONTROL_DATA_SELECTED, app_id);
app_control_reply_to_launch_request(reply, app_control,
APP_CONTROL_RESULT_SUCCEEDED);
app_control_destroy(reply);
}
}
STP@2015
19
}

Badges
n

A badge is an image displayed on the


application icon

STP@2015

20

To be continued

STP@2015

21

También podría gustarte