Samsung / Tizen-CSharp-Samples

Tizen C# Samples for Mobile, Wearable, and TV profiles.
Apache License 2.0
233 stars 226 forks source link

How to keep application Tizen Wearable in foreground #128

Open Abesoddy opened 4 years ago

Abesoddy commented 4 years ago

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.

sgchoi5 commented 4 years ago

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

Abesoddy commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.