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

本文详细介绍了在Symbian系统中如何通过URL下载、安装、运行和卸载Java程序,包括使用特定代码实现通过链接启动WAP浏览器下载JAR包,通过RApaLsSession接口进行安装,以及查找并启动Java应用的方法。
摘要由CSDN通过智能技术生成

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.卸载:

整理中.....

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值