언어 설정

Menu
Sites
Language
How to control the launch of some application [ App Lock ]

Hello Everyone, 

I rencently started a new project for developing a App Lock,

I want to understand how to launch an AppLock (my application) when some other application is launched by the user from launcher.
I tried with implicit application launch control but its not working proper Please help ! about What to use and How should I implement

Thanks, Dinal Jivani

 

답변 바로가기

Responses

16 댓글
Armaan-Ul- Islam

Most Probably Tizen Application Manager API offers the feature you are looking for.

Application Manager API References

Application Manager Guide

 

app_manager_set_app_context_event_cb()  registers a callback function to be invoked when the applications get launched or terminated.

Dinal Jivani

Thanks, Armaan-Ul- Islam

but, I had got this callback function but i am not getting the Exact Flow of the Code that how it works ,

can you please help me for How should I implement this ?

Thanks, Dinal Jivani 

Mark as answer
Armaan-Ul- Islam

Sure. I'm Sharing a Code Sample for you from my Understanding.....

 

void context_event_cb(app_context_h context, app_context_event_e event, void *user_data){
    char *app_id;
	int ret;

	ret = app_context_get_app_id(context, &app_id);

	if( event == APP_CONTEXT_EVENT_LAUNCHED){

		dlog_print(DLOG_DEBUG,LOG_TAG,"App Launched:%s",app_id);

		if(strcmp(app_id,"org.lock.testapp")==0){ // If matches with your desired app id to lock, You may use a Array/List here
			dlog_print(DLOG_DEBUG,LOG_TAG,"Locked app is Launched, Add Source Code here to Ask for Password");

			//if (password is ok)
				app_manager_resume_app (context);
			//else
				app_manager_request_terminate_bg_app(context);  // For Tizen 3.0 & higher
				app_manager_terminate_app(context);	// For Tizen 2.3.2 & lower
		}
	}

	else if( event == APP_CONTEXT_EVENT_TERMINATED)
	    dlog_print(DLOG_DEBUG,LOG_TAG,"App Terminated:%s",app_id);

}

void set_callbacks(){

	int ret=app_manager_set_app_context_event_cb(context_event_cb,NULL);

	if(ret == APP_MANAGER_ERROR_NONE)
		dlog_print(DLOG_DEBUG,LOG_TAG,"Callback Registered.");
	else {
		dlog_print(DLOG_DEBUG,LOG_TAG,"Callback Registration Error:%d",ret);
	}
}

static bool
app_create(void *data)
{
	appdata_s *ad = data;
	create_base_gui(ad);

    set_callbacks();

	return true;
}

 

Add appmanager.launch & appmanager.kill.bgapp/appmanager.kill privileges in your tizen-manifest.xml.

You may develop a Service app to do this task,  If you feel to do so.

Dinal Jivani

Thanks for the Help Armaan-Ul- Islam

looking at Code I think it will Only work if my App is Currently Running or may be in Resume Mode but If i Terminate my App It won't work 

I will be Back soon After checking the Code Stuff you provided, 

Thanks Dinal Jivani :D

Dinal Jivani

Hello Armaan-Ul- Islam,

First of all Thanks a lot for such help,

Here I am after using the Code Sample you shared above,

Its working all well, but only if my app is Running or Paused . as I said above , If my app is Terminated it Won't work Is there any solution for that?

Service Application is a solution but I'd never worked with that stuff, please help me to find a better way or just share a example of Service application if you think it fits to my requirement ....

Thanks Dinal Jivani

Armaan-Ul- Islam

You're Welcome.

 

Developing a Service application in Tizen much simple.

# Just Move the Codes above to Service app and invoke set_callbacks() function from service_app_create().

 

# Package the 'App lock Service App' with your 'App lock UI App'.

 Tizen Studio IDE > Right Click on your UI app on Project Explorer > Properties > Tizen-Studio > Package > Multi > Check Mark your Service App.

 

# If your service app don't launch automatically, Use the solution on this post:

https://developer.tizen.org/forums/sdk-ide/how-can-i-launch-ui-app-service-app-has-same-package-id.

 

# If your service app don't launch at each device reboot, try this Alarm API solution along with on-boot="true" and auto-restart="true" on tizen-manifest.xml.

https://developer.tizen.org/forums/native-application-development/wearable-start-service-application-restart

Dinal Jivani

Thank You, Armaan-Ul- Islam

 

It works all good as I want ....

but still facing one problem for Terminating the app and also removing it from Recent Apps,

as you shared a callback in your above code I had used :

app_manager_request_terminate_bg_app(context); // for terminating the context app

already added : http://tizen.org/privilege/appmanager.kill.bgapp privilege

but It won't terminate the App and still shown in Recent Apps list, How do I completely terminate the App

Thanks Dinal Jivani 

Dinal Jivani

and I am also facing some problem using Service Application ,

 as you said I called service Application using App control, and I had called set_callbacks() in the service_app_create() and Service application is launching successfully .

and it works good but after terminating my app (App Lock ) nearly after 10 seconds it stops working (Service App is not Terminating but stop working and responding) 

after that it do not responds to app_manager_set_app_context_event_cb() callback 

and my Locked app are launching, it is not responding to :

void context_event_cb(app_context_h context, app_context_event_e event, void *user_data);

 

Armaan-Ul- Islam

Service apps are killed by OS automatically for Optimization.

Go to tizen-manifest.xml of your service app > 'Advanced' tab > Add a Background Category (add any one that seems relevant).

That would add some priority to your service app.

 

Additionally, Use the Alarm API Solution mentioned on this post to restart the service app at time interval:

https://developer.tizen.org/forums/native-application-development/wearable-start-service-application-restart

 

Armaan-Ul- Islam
Dinal Jivani

Thanks a lot for the Guidance,Armaan-Ul- Islam

I'll be back after using this Code and Callbacks and using some tweaks to code .

Thanks, Dinal Jivani

 

Dinal Jivani

I am not gettng the any Answer for this questions , can you please help me for this one too,

This function is not able to terminate the app 

Dinal Jivani

There is one more Question in my Mind that can't we get the Resume & Pause event of app as Launch and Terminate ?

is that possible in any way ? to get call on app resume or pause ?

please help , Dinal Jivani

Thanks for the Help till now Armaan-Ul- Islam

 
 
 

 

Armaan-Ul- Islam

You're Welcome.

Seems app_context_event has only two possible event yet:

 

typedef enum {
    APP_CONTEXT_EVENT_LAUNCHED, /**< The application is launched */
    APP_CONTEXT_EVENT_TERMINATED, /**< The application is terminated */
} app_context_event_e;

 

There's 'app_manager_is_running()' function , But I'm afraid It may respond 'true' for both paused and resumed state. If not, then good for you.

 

About Termination, Check my response on this post:

https://developer.tizen.org/forums/native-application-development/exiting-app-using-app_id#comment-27363

Dinal Jivani

i had already had look at these struct members

typedef enum {
    APP_CONTEXT_EVENT_LAUNCHED, /**< The application is launched */
    APP_CONTEXT_EVENT_TERMINATED, /**< The application is terminated */
} app_context_event_e;

So, It means we can not get any trigger when application is clicked that is in paused State ?

Can we emulate this using any other API ?If Yes, then please help me out . 

 

Armaan-Ul- Islam

 "So, It means we can not get any trigger when application is clicked that is in paused State ?"

 

Yes, As far as I've seen The Tizen API Public Documentations , You can't yet.

Any other API rather 'Application Manager API' ? Most Probably "No".