언어 설정

Menu
Sites
Language
How to pass arguments to tizen native application?

I am trying to create a tizen native application which can launch another application. I wanted to create an application in such a way that I can give application name as a parameter to the application I am going to develop.

Following are the steps I have followed to understand how to pass command line arguments to the application and how to process the arguments in application:

  1. Added log statement to check on how many arguments are passed to my application
for (int i = 0; i < argc; i++)
{
pArgs->Add(*(new String(pArgv[i])));
AppLog("index : %d, argument : %s", i, pArgv[i]);
}
  1. Launched the application using launch_app in sdb -e shell
  • launch_app $hello_world_application (without arguments).

It is observed that the count of the arguments that are passed to osp_main are 6.

Logs :

11-14 20:11:37.411 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(24) > Application started, arg count : 6
11-14 20:11:37.411 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 0, argument : /opt/apps/Xbfv5mXrHt/bin/tizenSrvAppProject2
11-14 20:11:37.421 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 1, argument : `zaybxcwdveuftgsh`
11-14 20:11:37.421 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 2, argument : __AUL_STARTTIME__
11-14 20:11:37.421 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 3, argument : NAAAAAEEAAASAAAAX19BVUxfU1RBUlRUSU1FX18AEgAAADEzODQ0Mjc0OTYvNzU2OTM1AA==
11-14 20:11:37.421 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 4, argument : __AUL_CALLER_PID__
11-14 20:11:37.421 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : int OspMain(int, char **)(30) > index : 5, argument : KAAAAAEEAAATAAAAX19BVUxfQ0FMTEVSX1BJRF9fAAUAAAAzOTAzAA==
11-14 20:11:38.231 : INFO / tizenSrvAppProject2 ( 3904 : 3904 ) : virtual bool tizenSrvAppProject2App::OnAppInitializing(Tizen::App::AppRegistry &)(50) > Timer construct status : [E_SUCCESS]

  • launch_app Xbfv5mXrHt.tizenSrvAppProject2 "test1"

It is observed that the count of the arguments that are passed to osp_main are 6.

  • launch_app Xbfv5mXrHt.tizenSrvAppProject2 "test1" "test2"

It is observed that the count of the arguments that are passed to osp_main are 8.

also it is observed that the last argument that is passed to the application is not taken into consideration by the application.

Logs:

11-14 20:14:34.241 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(24) > Application started, arg count : 8
11-14 20:14:34.281 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 0, argument : /opt/apps/Xbfv5mXrHt/bin/tizenSrvAppProject2
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 1, argument : `zaybxcwdveuftgsh`
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 2, argument : test1
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 3, argument : HAAAAAEEAAAGAAAAdGVzdDEABgAAAHRlc3QyAA==
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 4, argument : __AUL_STARTTIME__
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 5, argument : MwAAAAEEAAASAAAAX19BVUxfU1RBUlRUSU1FX18AEQAAADEzODQ0Mjc2NzQvOTE0MjQA
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 6, argument : __AUL_CALLER_PID__
11-14 20:14:34.291 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : int OspMain(int, char **)(30) > index : 7, argument : KAAAAAEEAAATAAAAX19BVUxfQ0FMTEVSX1BJRF9fAAUAAAAzOTI1AA==
11-14 20:14:34.681 : INFO / tizenSrvAppProject2 ( 3926 : 3926 ) : virtual bool tizenSrvAppProject2App::OnAppInitializing(Tizen::App::AppRegistry &)(50) > Timer construct status : [E_SUCCESS]

 

Kindly provide me some pointers on:

How are arguments passed to osp_main?

How to make use of the arguments passed to the application by the application?

 

Thanks in Advance

 

Responses

8 댓글
Alex Ashirov

Hi,

Please take a look at this topic:

https://developer.tizen.org/forums/native-application-development/passing-parameters-when-starting-another-application

and hopefully this approach will work for you.

durgaprasad alaparthi

Hi,

Thanks for the reply. The link mentioned suggest how  to pass arguments to an application that is launched from an existing application.

However my requirement is as follows:

  1. Create an application in Tizen IDE.
  2. Launch the application (only one application) using "run as native application" from IDE or through command line interface in SDB using "launch_app" and pass arguments to the application.

Following are the things I am trying to identify:

  1. How to pass arguments to the application?
  2. In what order the arguments are received by the osp_main?
  3. How many arguments are given to osp_main when an application is launched?

 

Alex Dem

Hi,
As I know method LaunchApplication() with args is deprecated.
To deliver args you should register your requested  app like Application Control and inherit Tizen::App::IAppControlProviderEventListener interface.
Params should comes to OnAppControlRequestReceived() listener:

https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fapp%2Fdelivering_launch_arguments.htm

Here is article how to find requested app and launch its:
https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fapp%2Fresolving_appcontrols.htm

Here is one more article about interaction of caller app and requested app:
https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fapp%2Fhandling_appcontrol_request.htm

Alexey.

durgaprasad alaparthi

Thanks for the help. I have written a sample application using IAppControlProviderEventListener and am able to partially find out how the arguments are passed to the application.

Following are the steps followed:
1. Written a sample application using IAppControlProviderEventListener interface.
2. Executed the application by passing the arguments "test1" "test2" "test3" as parameterts.
3. Printed the logs.

Code Snippet:

void
tizenSrvAppProject2App::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String &operationId, const Tizen::Base::String *pUriData, const Tizen::Base::String *pMimeType, const Tizen::Base::Collection::IMap *pExtraData)
{
    AppLog("OnAppControlRequestReceived event handler");
	AppLog("request id : %ld", reqId);
	if(false == operationId.IsEmpty())
	{
		AppLog("operation id : %ls", operationId.GetPointer());
	}
	if((NULL != pUriData) && (false == pUriData->IsEmpty()))
	{
		AppLog("uridata : %ls", pUriData->GetPointer());
	}
	if((NULL != pMimeType) && (false == pMimeType->IsEmpty()))
	{
		AppLog("mimeType : %ls", pMimeType->GetPointer());
	}
	if(NULL != pExtraData)
	{
		int argc = pExtraData->GetCount();
		AppLog("extra data count : %d", argc);
		if(0 < argc)
		{
			IList* keyList = pExtraData->GetKeysN();
			int nKeys = keyList->GetCount();
			AppLog("Key count : %d", nKeys);
			for(int i = 0; i < nKeys; i++)
			{
				String* key = static_cast<String*>(keyList->GetAt(i));
				if((NULL != key) && (false == key->IsEmpty()))
				{
					AppLog("key : %ls", key->GetPointer());
				}
			}

			IList* valList = pExtraData->GetValuesN();
			int nValue = valList->GetCount();
			AppLog("value count : %d", nValue);
			for(int i = 0; i < nValue; i++)
			{
				String* val = static_cast<String*>(valList->GetAt(i));
				if((NULL != val) && (false == val->IsEmpty()))
				{
					AppLog("val : %ls", val->GetPointer());
				}
			}
		}
	}
}

 

Logs:

11-18 14:27:00.391 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(94) > OnAppControlRequestReceived event handler
11-18 14:27:00.401 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(95) > request id : 0
11-18 14:27:00.421 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(98) > operation id : http://tizen.org/appcontrol/operation/main
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(94) > OnAppControlRequestReceived event handler
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(95) > request id : 1
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(98) > operation id : http://tizen.org/appcontrol/operation/main
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(111) > extra data count : 2
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(116) > Key count : 2
11-18 14:27:30.871 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(122) > key : test1
11-18 14:27:30.881 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(122) > key : test2
11-18 14:27:30.881 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(128) > value count : 2
11-18 14:27:30.881 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(134) > val : test2
11-18 14:27:30.881 : INFO / argParsingSampleApp ( 2579 : 2579 ) : virtual void argParsingSampleAppApp::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(134) > val : test3

Observations:

1. Arguments are passed to the application in "OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String &operationId, const Tizen::Base::String *pUriData, const Tizen::Base::String *pMimeType, const Tizen::Base::Collection::IMap *pExtraData)" callback handler and are available as part of "const Tizen::Base::Collection::IMap *pExtraData" parameter.
2. Tried to print the keys and values of pExtraData and faced following issues.

  •    Facing compilation errors when trying to print values by using "GetValue(const Object& key)" API.
  •    The count of keys in the map are printed as 2 and the keys printed are "test1", "test2"
  •    The count of values in the map are printed as 2 and teh values printed are "test2", "test3"

   Please provide me pointers on:

  •    How to print values from keys using GetValue(const Object& key) API.
  •    Why are keys considered as 2 and "test1" and "test2" are considered as keys.
  •    Why are values considered as 2 and "test2" and "test3" are considered as values.

 

Alex Dem

Hi,

regarding GetValue api using try this code:

        Collection::IList* pKeyList;

        pKeyList=pExtraData->GetKeysN();

        for (int i=0;i<pKeyList->GetCount();i++)
        {
          String* key=(String*)pKeyList->GetAt(i);
          String* value=(String*)pExtraData->GetValue(*key);
          AppLog("OnAppControlRequestReceived=%S", key->GetPointer());
          AppLog("OnAppControlRequestReceived=%S", value->GetPointer());
        };
        delete pKeyList;

Alexey

durgaprasad alaparthi

Hi,

Thanks for the help. I have executed the code and am able to print both key and value without any issues. However I have observed the following behavior which I am not able to understand.

Following are the logs I have observed when I launch my application with  "launch_app I5fWGvXJ4m.tizensrvSampleProject3 "test1" "test2" "test3" "test4"" command.

11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(187) > Key = test1
11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(188) > Val = test2
11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(187) > Key = test2
11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(188) > Val = test3
11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(187) > Key = test3
11-19 13:29:58.222 : INFO / tizensrvSampleProject3 ( 2900 : 2900 ) : virtual void tizensrvSampleProject3App::OnAppControlRequestReceived(RequestId, const Tizen::Base::String &, const Tizen::Base::String *, const Tizen::Base::String *, const Tizen::Base::Collection::IMap *)(188) > Val = test4

From the logs it is observed that "test1" is considered as key and the value for the key is "test2". Similarly "test2" is considered as key and "test3" as value.

From this behavior, I am not sure how to pass arguments to the application so that Key value pairs are properly taken into consideration and can be accessed by the application.

 

Alex Dem

Hi,
I think you should launch requested app and deliver arguments another way:

At first add in requested app in tizenSrvAppProject2::OnAppInitializing (it is important to perform here, but not later) :
AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);

1) For explicit launch please please modify app caller this way :
    
using namespace Tizen::Base::Collection;
...
       
 HashMap extraData;
 extraData.Construct();
 String subjectKey1 = L"key1";
 String subjectVal1 = L"TestValue1";
 String subjectKey2 = L"key2";
 String subjectVal2 = L"TestValue2";

 extraData.Add(&subjectKey1, &subjectVal1);
 extraData.Add(&subjectKey2, &subjectVal2);

//here appId= Xbfv5mXrHt.tizenSrvAppProject2, operation does not matter
Tizen::App::AppControl* pAc = AppManager::FindAppControlN(L"Xbfv5mXrHt.tizenSrvAppProject2",
                                                          L"anyOpertion or Empty Content");
//String uri = L"custom";

if (pAc)
    {
       pAc->Start(null, null, &extraData, null);
       //pAc->Start(&uri, null, &extraData, null);
       delete pAc;
   }


2) For implicit launch you could use this approach:

  a) please add your own operation in manifest file of requested app (remove extra spaces):

            < AppControls >
                < AppControl >
                    < Operation >http://tizen.org/appcontrol/operation/custom< /Operation >
                < /AppControl >
            < /AppControls >

or you could use any another predefined operation but add your own uri, mime-type also, in this case you will need to them in FindAndStart ()  method
   b) modify caller app code:

      using namespace Tizen::Base::Collection;
     ...
       
      HashMap extraData;
      extraData.Construct();
      String subjectKey1 = L"key1";
      String subjectVal1 = L"TestValue1";
      String subjectKey2 = L"key2";
      String subjectVal2 = L"TestValue2";

      extraData.Add(&subjectKey1, &subjectVal1);
      extraData.Add(&subjectKey2, &subjectVal2);


      AppControl::FindAndStart  (L"http://tizen.org/appcontrol/operation/custom", null,  null, null, &extraData, null);

After these steps you will able to deliver launch args in requested app.
Alexey.

durgaprasad alaparthi

Hi,

Thanks for the input. I will try the steps mentioned above. However my requirement is to launch an application with arguments from command line.

Example: > launch_app application arg1 arg2 arg3 arg4

I have tried to read the arguments from the below API

void
tizenSrvAppProject2App::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String &operationId, const Tizen::Base::String *pUriData, const Tizen::Base::String *pMimeType, const Tizen::Base::Collection::IMap *pExtraData)

However following output is seen when try to print arguments from pExtraData

Count of arguments in pExtraData = 3

Key value
arg1 arg2
arg2 arg3
arg3 arg4

However it is expected to be as follows

Count of arguments in pExtraData = 2

key value
arg1 arg2
arg3 arg4

Please provide me some pointers to arrive as expected above.