Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep application Tizen Wearable in foreground #128

Open
Abesoddy opened this issue Jan 22, 2020 · 8 comments
Open

How to keep application Tizen Wearable in foreground #128

Abesoddy opened this issue Jan 22, 2020 · 8 comments

Comments

@Abesoddy
Copy link

Abesoddy commented Jan 22, 2020

Hello,

I'm sorry if this is bad place to ask this question. Do you have a solution to keep a Tizen Wearable C# application in foreground when the screen goes to sleep ?

I would like to develop an activity tracker for sport and therefore always have the application visible but not necessarily the screen on.

Thank you for your answers.

@Abesoddy Abesoddy changed the title How to keep application in foreground How to keep application Tizen Wearable in foreground Jan 22, 2020
@sgchoi5
Copy link
Contributor

sgchoi5 commented Jan 23, 2020

Hello,
You need to use "Service Application".
Refer to this sample,
https://github.com/Samsung/Tizen-CSharp-Samples/tree/master/Wearable/ServiceApp

@Abesoddy
Copy link
Author

Hello,

Thank you for your answer !

I don't really understand how to implement it. The service must listen to the event when the screen goes to sleep and must wake up the application?

Sorry i don't know Tizen well yet...

@Abesoddy
Copy link
Author

Abesoddy commented Jan 28, 2020

Hello,

I just implemented the following code for launch service app :

appControl = new AppControl { ApplicationId = Constants.serviceId, Operation = AppControlOperations.Default }; AppControl.SendLaunchRequest(appControl);

I would like to stop the service but I can't find a way to stop ... I tried :

AppControl.SendTerminateRequest(appControl)

But not working...

@hjhun
Copy link

hjhun commented Jan 29, 2020

Hello,
To terminate the running application in the background, please use ApplicationManager.TerminateBackgroundApplication() instead of AppControl.SendTerminateRequest().
https://samsung.github.io/TizenFX/API6/api/Tizen.Applications.ApplicationManager.html#Tizen_Applications_ApplicationManager_TerminateBackgroundApplication_Tizen_Applications_ApplicationRunningContext_
Before using the method, please add the following privilege on tizen-manifest.xml:
Privilege
http://tizen.org/privilege/appmanager.kill.bgapp

AppControl.SendTerminateRequest() is for handling sub-applications of app-group feature.
Remarks
You are not allowed to terminate other general applications using this API. This API can be used to terminate sub-applications, which were launched as a group mode by the caller application. Once the callee application is being terminated by this API, other applications, which were launched by the callee application as a group mode will be terminated as well.

@Abesoddy
Copy link
Author

Hello,

Unfortunately the minimum version of API is 6 for this method...

Isn't there another solution to keep the application in the foreground ? Some apps like Strava for example stay in the foreground all the time.

Thank you for your answers.

@hjhun
Copy link

hjhun commented Jan 29, 2020

Hello,

The application cannot terminate another application(running in the foreground) directly by policies.
If the target application is yours, you can use AppControl.ExtraData to define a new protocol to terminate.

The following code is a sample for handling the termination request:

protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
{
    base.OnAppControlReceived(e);
    
    var recvAppCtrl = e.ReceivedAppControl;
    var value = recvAppCtrl.ExtraData.Get<string>("TERM");
    if (value == "true")
    {
        Log.Warn("App", "Exit");
        Exit();
     }
}

The following code is a sample for sending the launch request with "TERM" ExtraData of AppControl:

AppControl appControl = new AppControl();
appControl.ApplicationId = "org.tizen.helloword";
appControl.ExtraData.Add("TERM", "true");
AppControl.SendLaunchRequest(appControl);

@Abesoddy
Copy link
Author

Hello,

Indeed it is a solution, thank you very much for your help !

However, we always notice that the application is closed and then opens when the screen turns on. What we don't see on apps like Strava or Endomondo (sports apps)...

@hjhun
Copy link

hjhun commented Feb 5, 2020

Hello.
I'm sorry too late first.

However, we always notice that the application is closed and then opens when the screen turns on. What we don't see on apps like Strava or Endomondo (sports apps)...
=> Do you mean when the screen turns on, the homescreen app is shown?

Do you use Galaxy Gear?
When the screen turns off (and then, after 20 seconds), the homescreen app is launched to raise the window of the homescreen app.
If it's...
Unfortunately, there is no way now. (Because, it's a product policy.)
The Samsung developer site mentions "Reserved screen manager API" about that. But, it's native API for C/C++ applications.

I recommend a workaround that uses Display API.
https://samsung.github.io/TizenFX/API4/api/Tizen.System.Display.html

If you use Display.StateChanged, you can get the information about display state.
The delegate will be called when the display state is changed.
When the display state is "Normal"(Normal state), you should send a launch request to raise the window of the application. (using AppControl API).
Please consider using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants