android resolves the apk file on SD card

Source: Internet
Author: User

public  void  parseapk  (context context, String Apkfilepath) {    Packagemanager Packagemanager = Context.getpackagemanager ();    PackageInfo PackageInfo = Packagemanager.getpackagearchiveinfo (Apkfilepath, 0 ); if  (PackageInfo! = null )        {packageInfo.applicationInfo.sourceDir = Apkfilepath;        PackageInfo.applicationInfo.publicSourceDir = Apkfilepath;        String name = PackageInfo.applicationInfo.loadLabel (Packagemanager). toString ();        String PackageName = packageinfo.packagename;        String versionname = packageinfo.versionname;        int  versioncode = Packageinfo.versioncode;    drawable icondrawable = PackageInfo.applicationInfo.loadIcon (Packagemanager); }}

Note that you have to set ApplicationInfo SourceDir and Publicsourcedir after you get packageinfo, otherwise you will output the following error message and throw an exception when you read the label.
Failure retrieving text 0x7f050000 in package com.taskkiller.demo

When you read the icon, it will output the following error message and throw an exception.
Failure retrieving icon 0x7f020005 in package com.sample.radio

This is because both the label and the icon are in the resource, and the information inside the resource cannot be read without setting SourceDir and Publicsourcedir

android resolves the apk file on SD card

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.