Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何编程卸载主题

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60
Compatibility
Platform(s): Symbian
S60 5th Edition
Article
Keywords: RAknsSrvSession EnumerateSkinPackagesL CAknsSrvSkinInformationPkg RSisRegistrySession InstalledPackagesL CSisRegistryPackage RSWInstLauncher CustomUninstall SilentCustomUninstall
Created: chenziteng (27 Mar 2010)
Last edited: hamishwillee (22 Nov 2011)

Contents

注意

1. RAknsSrvSession和CAknsSrvSkinInformationPkg是扩展皮肤API的一部分,可以在SDK API Plug-in中找到。

2. RSWInstLauncher是SW Installer Launcher API的一部分,也可以在SDK API Plug-in中找到。

3. RSisRegistrySession和CSisRegistryPackage是Symbian/S60内部API,如需要用作商业用途请加入S60 API Partnering Program并向诺基亚购买。

简介

本文以一个完整的示例程序为例说明了如何实现以下用例:应用程序列举所有的主题(皮肤),并允许用户选择和卸载它们。

方法

1. 应用程序使用RAknsSrvSession::EnumerateSkinPackagesL()枚举所有主题,然后将它们的信息填充到一个列表框中,例如下面的代码将所有主题的名字逐一添加到了列表框中。

...
TInt err = iAknsSrvSession.Connect(this); // 连接AVKON皮肤服务器
User::LeaveIfError(err);
...
User::LeaveIfNull(iListBox);
if(iAknsSrvSkinInformationPkgs!=NULL) // 清空皮肤信息包数组
{
iAknsSrvSkinInformationPkgs->ResetAndDestroy();
}
delete iAknsSrvSkinInformationPkgs;
iAknsSrvSkinInformationPkgs = NULL;
 
CTextListBoxModel* model = iListBox->Model();
CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
itemArray->Reset(); // clear the listbox
iListBox->HandleItemRemovalL();
 
iAknsSrvSkinInformationPkgs = iAknsSrvSession.EnumerateSkinPackagesL(EAknsSrvAll); // 重新获取所有的皮肤信息包
TInt count = iAknsSrvSkinInformationPkgs->Count();
for(TInt i=0;i<count;i++)
{
const CAknsSrvSkinInformationPkg& pkg = *((*iAknsSrvSkinInformationPkgs)[i]);
TBuf<512> listString;
CreateListBoxItemL( listString, pkg.Name()); // 将主题的名字添加到列表框中
AddListBoxItemL( iListBox, listString );
}
if(count>0)
{
iListBox->SetCurrentItemIndexAndDraw(0);
}

2. 当用户在列表框中选中某个主题并选择移除它时,应用程序首先调用RSisRegistrySession::InstalledPackagesL()枚举所有已安装的安装包(jar包和sis包等),然后逐一将它们的名字(CSisRegistryPackage::Name)与用户选中的主题的名字(CAknsSrvSkinInformationPkg::Name)相比较,如果找到匹配的项那么它就是该主题的安装包。知道了安装包的注册信息(尤其是UID)之后,应用程序就能调用RSWInstLauncher::CustomUninstall()卸载主题了。

...
User::LeaveIfNull(iListBox);
User::LeaveIfNull(iAknsSrvSkinInformationPkgs);
TInt index = iListBox->CurrentItemIndex(); // 获取用户选择的主题列表框索引
if(index<0||index>=iAknsSrvSkinInformationPkgs->Count())
{
User::Leave(KErrNotFound);
}
 
const CAknsSrvSkinInformationPkg& pkg = *((*iAknsSrvSkinInformationPkgs)[index]); // 获取主题信息包
 
TUid uid = KNullUid;
Swi::RSisRegistrySession session;
TInt err = session.Connect(); // 连接sis registery server
User::LeaveIfError(err);
CleanupClosePushL(session);
RPointerArray<Swi::CSisRegistryPackage> sisPkgs;
session.InstalledPackagesL(sisPkgs); // 获取所有已安装的安装包的信息,需要ReadUserData能力
TInt count = sisPkgs.Count();
for(TInt i=0;i<count;i++)
{
Swi::CSisRegistryPackage& sisPkg = *(sisPkgs[i]);
// 通过比较名字确定是不是用户所选主题的安装包
if(sisPkg.Name()==pkg.Name())
{
uid = sisPkg.Uid(); // 如果是则记下安装包的UID和索引
index = sisPkg.Index();
break;
}
}
sisPkgs.ResetAndDestroy();
sisPkgs.Close();
CleanupStack::PopAndDestroy(&session);
 
if(uid==KNullUid)
{
User::Leave(KErrNotFound);
}
 
SwiUI::RSWInstLauncher installer;
User::LeaveIfError( installer.Connect() );
CleanupClosePushL( installer );
SwiUI::TOpUninstallIndexParam params;
params.iUid = uid;
params.iIndex = index;
SwiUI::TOpUninstallIndexParamPckg pckg( params );
SwiUI::TOperation operation( SwiUI::EOperationUninstallIndex );
SwiUI::TUninstallOptions uninstallOptions;
SwiUI::TUninstallOptionsPckg optPckg( uninstallOptions );
err = installer.CustomUninstall( operation, pckg,SwiUI::KSisxMimeType() ); // 然后就能移除主题了
// 也可以静默移除(不需要用户交互)
// err = installer.SilentCustomUninstall( operation, optPckg, pckg,SwiUI::KSisxMimeType() );
if(err!=SwiUI::KSWInstErrUserCancel) // 如果有用户交互的话,用户可能取消卸载操作
{
User::LeaveIfError(err);
}
CleanupStack::PopAndDestroy( &installer );
...

关于不能卸载已签名的主题

以上代码在卸载已签名的主题会失败,只需要将

	SwiUI::TOpUninstallIndexParam params;
params.iUid = uid;
params.iIndex = index;
SwiUI::TOpUninstallIndexParamPckg pckg( params );
SwiUI::TOperation operation( SwiUI::EOperationUninstallIndex );
SwiUI::TUninstallOptions uninstallOptions;
SwiUI::TUninstallOptionsPckg optPckg( uninstallOptions );
err = installer.CustomUninstall( operation, pckg,SwiUI::KSisxMimeType() ); // 然后就能移除主题了

修改为

err = installer.Uninstall(uid,SwiUI::KSisxMimeType());

便可以正常使用.

示例程序

完整的示例程序: GoodbyeHell(UninstallSelectedTheme).zip

为了使该示例程序能够在S60第五版SDK上构建,示例程序中附了一份必需的头文件和库文件,它们是从SDK plug-in和Symbian PDK中拷贝的。该示例程序在S60第五版模拟器和一台手机上测试通过,但它仅仅是一个示例,没有任何稳定性和兼容性的保证。

如何使用:

1. 在手机上安装一个主题(例如aquarius multicolor)

2. 在手机上安装示例程序GoodbyeHell(UninstallSelectedTheme).zip\GoodbyeHell\sis\GoodbyeHell.sisx

3. 启动示例程序,然后从它提供的主题列表中选择1.中安装的主题,并选择“Options”->“Uninstall”,然后按提示卸载该主题。

参考文档

How to uninstall themes programmatically

SDK API Plug-in

Extended Skins API

SW Installer Launcher API

Tools&Kits

This page was last modified on 22 November 2011, at 06:30.
83 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×