Languages

Menu
Sites
Language
How to keep Native app on top when screen on?

Is there anyway to keep mobile app is always on top when screen on 

Responses

6 Replies
Shaswati Saha

Hello,

You may follow the process below to implement this.

Step 1: At first, create two different apps i.e. one UI app (which will remain on top at screen on state) and one service app (which will detect the screen state whether it's on/off within a certain time interval and launch the UI app).

Step 2 : The tasks of service app described in Step 1 can be done by using Ecore Timer and App Control. In the service_app_create function of the service app write the code below:

ecore_timer_add(5, get_device_screen_state, NULL);

Here, I'm checking the state of screen within 5 sec interval, you may change the value according to your requirement. The get_device_screen_state function can be written as below:

Eina_Bool get_device_screen_state(void *data EINA_UNUSED) {
    display_state_e state;

	if(device_display_get_state(&state) == DEVICE_ERROR_NONE) {
		switch(state) {
		case DISPLAY_STATE_NORMAL:
			launchUIapp(); // function to make the UI app visible to user
			break;
		case DISPLAY_STATE_SCREEN_DIM:
			break;
		case DISPLAY_STATE_SCREEN_OFF:
			break;
		}
	} else {
		// error handling
	}
	return EINA_TRUE;
}

After that write function as below:

static void launchUIapp()
{
    app_control_h app_control = NULL;
	app_control_create(&app_control);
	app_control_set_app_id(app_control, "GIVE_THE_UI_APP_ID");

	if(app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE)
	{
		// app launched successfully
	}

	app_control_destroy(app_control);
}

NOTE: Don't forget to add the following previleges in the manifest file of the service app:

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

Headers need to be included in the service app:

#include <device/display.h>
#include <device/callback.h>
#include <Ecore.h>

Ref. Links:

https://developer.tizen.org/dev-guide/native/2.3.0/org.tizen.mobile.native.apireference/group__Ecore__Timer__Group.html#ga7b9cb9d24ecebfdbb957436e2e669402

https://developer.tizen.org/zh-hans/community/code-snippet/native-code-snippet/get-device-screen-state?langredirect=1

https://developer.tizen.org/development/api-guides/native-application/application-framework/application/app-control

HD Nguyen

Thanks so much for your solution.

Shaswati Saha

Did you make it work? What's the status right now?

HD Nguyen

I think there is an other simple solution (example: use library) instead of implement logic flows.

Anyway, your solution is also good. Thanks one more times.

Shaswati Saha

Would you please share the alternate solution here? I'll be really glad to know that.

HD Nguyen

Sorry, I just think about that but I have not yet.