個人整理原創,如要轉載,請註明去處!以下無特殊說明,都是針對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)
);
}
}