(Android plugin) Get the resource summary in the jar package

Source: Internet
Author: User
Document directory
  • Requirement Description:
  • Package Resources
  • 1. Read the resource files in the jar package through the AssetManager class
  •  
  • Use the ClassLoader class to read resource files
  •  
Requirement Description:

During project development, You Need To package public resources into jar packages, and the subsequent apps directly import jar packages into the project to share public resources.

Package Resources

Package project resources, including class, assets, res

 

1. Read the resource files in the jar package through the AssetManager class

The AssetManager class provides an interface for reading files and xml files.

Note: The restriction is that the file to be read must be placed in the Assets folder.

 

The following is an example of reading resources.

Public static Drawable getAssertDrawable (Context context, String fileName) {try {InputStream inStream = context. getAssets (). open (fileName); return new BitmapDrawable (BitmapFactory. decodeStream (inStream);} catch (IOException e) {Log. e (LOG_TAG, "Assert" + fileName + "does not exist");} return null ;}
Use the ClassLoader class to read resource files

The classLoader class provides interfaces for reading resource paths and resources (in stream form.

The difference between the classLoader class and the AssetManager class is that the classLoader class can also read Resources in the res folder.

 

 

The following is a small example of ClassLoader reading resources.

  BufferedImage image=ImageIO.read(ClassLoader.getSystemResourceAsStream(“/res/drawable/icon.png”));

 

 

 

Related Article

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.