个人整理原创,如要转载,请注明去处!以下无特殊说明,都是针对symbian第三版。
1)安装第三方程序:
void CFunctions::InstallJarFileL(const TDesC& aFilePath)
{
RApaLsSession apaSession;
User::LeaveIfError(apaSession.Connect());
TDataType dataType(_L8("text/vnd.sun.j2me.app-descriptor")); //jar
//TDataType dataType(_L8("application/vnd.symbian.install"));//sis
TThreadId threadID2;
apaSession.StartDocument(aFilePath, dataType, threadID2);
apaSession.Close();
}
2)启动第三方程序
void CFunctions::RunAppL(const TDesC& appPath)
{
CApaCommandLine *cmd = CApaCommandLine::NewLC();
cmd->SetCommandL(EApaCommandRun);
cmd->SetExecutableNameL(appPath);
RApaLsSession als;
User::LeaveIfError(als.Connect());
CleanupClosePushL(als);
User::LeaveIfError(als.StartApp(*cmd));
CleanupStack::PopAndDestroy(2);
}
//查找并启动第三方程序
void CFunctions::FindRunAppL(const TDesC& appName)
{
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> fileName;
// 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++;
fileName.Copy(appInfo.iCaption);
if (fileName.Compare(appName) == 0) //注:appName 是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;
}
}
RunAppL(appPath);
}
else
{
informationNote->ExecuteLD(_L("Failed to search for MIDLET"));;
}
appSession.Close();
}
3)获得jar程序图标
根据MIDP 2.0特性,MIDIet图标必须包含在JAR中,如JAD文件中用到的MIDIet<n>属性。“JAR中的图标必须使用PNG图片,路径为大小写敏感的绝对路径”
因为JAR已经包含了图标,因此无法从文件中获取图标信息,但可以用MAknsSkinInstance从S60菜单获取MIDIet图标
RApaLsSession iApaSession;
TApaAppInfo appInfo;
iApaSession.GetAllApps();
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
for(TInt i= 0; i < iAppCount; i++)
{
iApaSession.GetNextApp(appInfo);
//Filtering through the list to get Midlets from the list of applications
if(appInfo.iFullName.Right(8).Compare(_L(".fakeapp"))==0)
{
appInfo.iFullName; //Gives Name of the Midlet
appInfo.iUid; //Gives Uid of the Midlet
TRAPD(Err,
CFbsBitmap* midletIcon, midletIconMsk;
AknsUtils::CreateAppIconLC(skin,
appInfo.iUid,EAknsAppIconTypeList,
midletIcon,
midletIconMsk);
// midletIcon and midletIConMsk has the Icon and Mask respectively.
(Print them to see the icon)
);
}
}