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

本文详细介绍了在Symbian系统中如何通过URL下载、安装、运行和卸载Java程序,包括使用特定代码实现通过链接启动WAP浏览器下载JAR包,通过RApaLsSession接口进行安装,以及查找并启动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.卸载:

整理中.....

最简单的安装方法:首先,读卡器或数据线“大容量存储模式”连接: 1:电脑上操作:将程序COPY到存储卡的others(其他); 2:手机上操作:应用程序---文件管理---选择存储卡---其他---找到该程序后点击它安装即可。 3:安装好的程序在这里:应用程序 JAVA游戏的安装须知:【 新手必看】  1:安装JAR程序游戏时,JAR文件名不能含有汉字,否则无法运行,请将文件名改成英文或拼音后安装。 2:将某些JAR安装到存储卡时,出现安装进度条到80%停止或死机的情况,但可以安装到手机内存。一般是存储卡兼容性不太好,建议格卡或换卡。 另外:关于JAR游戏安装出现“证书错误”时,不妨用这个方法试试: 大家知道,JAR游戏是不需要签名的,但出现“证书错误” ,应该是手机里自带的证书冲突,也就是也许你安装了某个软件在E盘,而他自带了某个证书,而机器只认C盘的证书,所以就发生系统错误了.(但JAR可以装手机里)说明可能是该JAR不支持安装这个机型,另外极有可能就是存储卡的问题, 解决方法如下: 把存储卡连上电脑后,找到存储卡的属性(鼠标右键最后一个)----工具----运行碎片整理一次(一般问题在这里就解决了)就能安装JAR软件了!如果还不行的话,进行多一步,找到存储卡的属性单击右键→属性→工具→有一个查错(选中)→然后把自动修复那项打上勾(另一个不要打!)→然后扫描等他查完 ……应该问题解决了!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值