Symbian程序如何下载安装jar,并启动java程序实践总结

symbian程序对java程序的可能的操作分为以下几种:

1.通过URL下载Jar包(Jad类似);

2.安装:分为系统自动安装与通过symbian程序安装;

3.运行;

4.卸载:

 

以下贴出实现的代码:

1.通过URL下载Jar包(Jad类似);

_LIT(KJarUrl,"http://xxx.xxx.xxx.xxx/test.jar");

CJavaInstallAndRunTestAppUi::LaunchWapBrowerL(KJarUrl);

 

void CJavaInstallAndRunTestAppUi::LaunchWapBrowerL(const TDesC& aAddr)
 {
  const TInt KPhoneUidWmlBrowser = 0x10008D39;
  TUid BrowserUid(TUid::Uid( KPhoneUidWmlBrowser ) );
  TApaTaskList taskList(CEikonEnv::Static()->WsSession());//Accesses tasks running on a device.
  TApaTask task = taskList.FindApp(BrowserUid);
 
  if (task.Exists())//测试任务是否存在
  {
   HBufC8* param8;
   param8 = HBufC8::NewLC( aAddr.Length()+2 );
   param8->Des().Append( _L("4 ") );
   param8->Des().Append( aAddr );
  
   task.SendMessage( TUid::Uid( 0 ), *param8 ); // UID is not used
   CleanupStack::PopAndDestroy(param8);
  }
  else
  {
   RApaLsSession iApaLsSession;
   if (!iApaLsSession.Handle())
   {
    User::LeaveIfError(iApaLsSession.Connect());
   }
   TThreadId thread;
   TBuf<512> url;
   url.Append(_L("4 "));
   url.Append( aAddr );
   User::LeaveIfError(iApaLsSession.StartDocument(url,BrowserUid, thread));
  }
 }

 

2.安装:(因为通过上面步骤下载完jar包后,系统会自动安装该包,所以我们只谈通过程序如何来安装这个包)

代码如下:

    RApaLsSession apaSession;
    User::LeaveIfError(apaSession.Connect());
    TDataType dataType(_L8("text/vnd.sun.j2me.app-descriptor"));
    TThreadId threadID2;
    apaSession.StartDocument(_L("c://test.jar"), dataType, threadID2);
    apaSession.Close();

 

3.运行;

代码如下:

    CAknInformationNote* informationNote;
   informationNote = new ( ELeave ) CAknInformationNote;
   
   RApaLsSession appSession;
   if( appSession.Connect() == KErrNone && appSession.GetAllApps() == KErrNone )
   {
    TApaAppInfo appInfo;
    TInt result = KErrNone;
    TInt handeled = 0;
    TInt count = 0;
    TBuf<256> appPath( _L(""));
    TBuf<64> appName;

    const HBufC* textAppName = StringLoader::LoadLC(R_APPNAME_TEXT);
    // Find the path to the midlets app file, that gets created
    // when the midlet is installed
    while( result != RApaLsSession::ENoMoreAppsInList )
    {
     if( result == KErrNone ) result = appSession.GetNextApp( appInfo );

     // GetNextApp ocasionally fails, hence the use of
     // handeled and count.
     if( result == KErrNone && count == handeled )
     {
      handeled++;
      count++;
      appName.Copy( appInfo.iCaption );

      if( appName.Compare(_L("test")) == 0) //注:test是java程序的名称,即Application name
      {
      // Found the app we we're looking for.
      appPath.Copy( appInfo.iFullName );
      result = RApaLsSession::ENoMoreAppsInList;
      }
     }
     else if( result == RApaLsSession::EAppListInvalid )
     {
      // Something failed, so the session is restarted.
      count = 0;
      appSession.Close();
      if( appSession.Connect() == KErrNone && appSession.GetAllApps() == KErrNone )
       result = KErrNone;
     }
    }
    CApaCommandLine * cmd1=CApaCommandLine::NewL();
    cmd1->SetExecutableNameL( appPath );
    cmd1->SetCommandL(EApaCommandRun);
    // Start the midlet
    if( appSession.StartApp(*cmd1) == KErrNotFound )
     informationNote->ExecuteLD(_L("MIDLET not found"));
    informationNote->ExecuteLD(appName);    
   }
   else
   {
    informationNote->ExecuteLD(_L("Failed to search for MIDLET"));;
   }
   appSession.Close();

 

4.卸载:

整理中.....

你可能感兴趣的:(Symbian开发)