android之PackageManager簡單介紹

來源:互聯網
上載者:User

標籤:android   style   http   color   os   io   java   ar   檔案   

PackageManager相關

      本類API是對全部基於載入資訊的資料結構的封裝,包含下面功能:

安裝,卸載應用查詢permission相關資訊

查詢Application相關資訊(application,activity,receiver,service,provider及對應屬性等)

查詢已安裝應用

添加?,刪除permission

清除使用者資料、緩衝,程式碼片段等

/** * PackageManager介紹: * 本類API是對全部基於載入資訊的資料結構的封裝,包含下面功能: * 安裝,卸載應用 查詢permission相關資訊 查詢Application相關 * 資訊(application,activity,receiver,service,provider及對應屬性等) * 查詢已安裝應用 添加?,刪除permission 清除使用者資料、緩衝,程式碼片段等 非查詢相關的API須要特定的許可權。 * 主要包括了,安裝在當前裝置上的應用程式套件的相關資訊 * 例如以下:擷取已經安裝的應用程式的資訊 */private HashMap<String, String> installPackagesInfo(){// 擷取packageManager對象PackageManager packageManager = this.getPackageManager();/*getInstalledApplications 返回當前裝置上安裝的應用程式套件集合 * ApplicationInfo相應著androidManifest.xml中的application標籤。通過它能夠擷取該application相應的資訊 */List<ApplicationInfo> applicationInfos = packageManager.getInstalledApplications(0);HashMap<String, String> resultMap = new HashMap<String, String>();Iterator<ApplicationInfo> iterator = applicationInfos.iterator();while(iterator.hasNext()){ApplicationInfo applicationInfo = iterator.next();String packageName = applicationInfo.packageName;// 包名String packageLabel = packageManager.getApplicationLabel(applicationInfo).toString();//擷取labelresultMap.put(packageLabel, packageName);}return resultMap;}

 另外在PackageManager類中,我們發現了幾個非常好玩的方法。

 

  

 

XMLResourceParse getXml(String packageName,int resid,ApplicationInfo appInfo)能夠從指定的包中載入某個xml檔案。

android之PackageManager簡單介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.