Method, device and medium for adapting application package for different devices based on android

By separating the basic resource package and the resolution image resource package, the application identifies the device resolution and downloads the corresponding resources upon startup, solving the problem of excessively large Android application package sizes and achieving efficient resource management and downloading.

CN115756523BActive Publication Date: 2026-04-21FUJIAN NEWLAND PAYMENT TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
FUJIAN NEWLAND PAYMENT TECH
Filing Date
2022-12-08
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

To adapt to different device screen resolutions, existing Android application packages need to store multiple sets of image resources with different resolutions, resulting in excessively large package sizes. Furthermore, all image resources must be downloaded at once, making it impossible to download only the images corresponding to the specified resolution.

Method used

The basic resource package and resolution image resource package are created separately. When the application starts, it identifies the device resolution and downloads the corresponding resource package, prioritizing the loading of image resources of the corresponding resolution to avoid loading incompatible resources.

Benefits of technology

Significantly reduce application package size, by up to 50% or more, improve download efficiency, and load only necessary image resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115756523B_ABST
    Figure CN115756523B_ABST
Patent Text Reader

Abstract

The application discloses a method for adapting different device application packages based on Android, which comprises the following steps: step 1, making a basic resource package and picture resource packages with different resolutions; step 2, packaging the basic resource package and an identification code into an application package; step 3, installing the application package, and when starting the application for the first time, identifying the resolution corresponding to the target device according to the identification code, and downloading the picture resource package with the corresponding resolution; step 4, loading the basic resource package in the application package and the downloaded picture resource package into a running memory; step 5, taking over the creation of an Android interface through an interface controller, and configuring the way of obtaining pictures under the Android interface; and step 6, obtaining target pictures from the running memory according to the way of obtaining pictures. The application can greatly reduce the size of the application package, and only needs to load the picture resource package adapted to the target device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Android system technology, and in particular to methods, devices and media for adapting Android application packages to different devices. Background Technology

[0002] With the development of the Android phone market, there are more and more types of Android phones on the market, with various screen resolutions. Developing an Android application requires adapting to different phone resolutions in order to run normally on most phones.

[0003] To adapt to different phone screen resolutions, Android applications commonly create multiple images of the same image at different resolutions and store them in corresponding resource folders such as drawable-hdpi, drawable-xhdpi, and drawable-xxhdpi. Using a built-in Android system mechanism, the application automatically selects the image from the folder path closest to the screen resolution on different phones and loads it.

[0004] In a packaged Android application, images occupy the largest amount of space. For example, a 100kb image may require multiple images of different resolutions to adapt to the application, with sizes of 25kb, 50kb, 100kb, 200kb, 400kb, or even more. In an application installation package, images can occupy up to 80% of the space if there are many images.

[0005] An application package typically stores m1 images at resolution M1, m2 images at resolution M2, m3 images at resolution M3, and so on. When an application needs to adapt to larger phone screen types and has more complex functionality, there may be more than ten sets of image resources for different resolutions. To adapt to different device (phone) resolutions, a large number of images need to be added. Due to the variety of resolutions, the number of images becomes enormous, resulting in a large application package size and high storage space consumption. Ideally, there should be multiple sets of image resources at different resolutions, but for a specific phone, only the set of images suitable for its screen resolution is needed; the others are unnecessary. However, current practices require downloading images for all resolutions during application package installation, instead of just downloading images for the desired resolution. Summary of the Invention

[0006] In view of this, the purpose of this invention is to propose a method for adapting Android application packages to different devices, so that devices (phones) with corresponding resolutions only load the set of image resource packages adapted to them, without loading image resource packages that are not compatible with the device, which can greatly reduce the size of the application package, and can reduce the size of the application package by up to 50% or more.

[0007] To achieve the above-mentioned technical objectives, the technical solution adopted by this invention is: a method for adapting Android application packages to different devices, comprising the following steps:

[0008] Step 1: Create a basic resource pack and image resource packs at different resolutions;

[0009] Step 2: Package the basic resource package and identification code into an application package;

[0010] Step 3: Install the application package. When the application is launched for the first time, the resolution corresponding to the target device is identified according to the identification code, and the image resource package of the corresponding resolution is downloaded.

[0011] Step 4: Load the basic resource package and the downloaded image resource package from the application package into the runtime memory;

[0012] Step 5: Take over the creation of the Android interface through the interface controller and configure the method of obtaining images under the Android interface;

[0013] Step 6: Obtain the target image from the running memory according to the image acquisition method.

[0014] Furthermore, step 1 specifically includes:

[0015] Step 11: Create a basic resource package, which contains a plurality of images with different names;

[0016] Step 12: Determine whether each image needs to be adapted to different resolutions. If so, modify the image to an n*n size identifier image and proceed to Step 13; otherwise, use the image as the base image and do not make any modifications.

[0017] Step 13: Create image resource packages of different resolutions. Based on the name and quantity of each of the identified images, store supplementary images of the corresponding resolution with the same name and quantity as the identified images in the image resource packages of different resolutions.

[0018] Furthermore, step 2 is followed by:

[0019] Step 21: Package the image resource packages of different resolutions separately and store them in the background.

[0020] Furthermore, step 4 specifically includes:

[0021] Step 41: When the application is launched, the Android system automatically loads the basic resource package in the application package into the running memory by default;

[0022] Step 42: Create a resource object and load the downloaded image resource package into the runtime memory through the resource object.

[0023] Furthermore, in step 5, the method for obtaining images under the Android interface is configured as follows: the priority order of the image resource package is set to be greater than that of the basic resource package, or the priority order of the basic resource package is set to be greater than that of the image resource package.

[0024] Furthermore, when the priority order of the image resource package is set to be higher than that of the basic resource package, the image with the corresponding name is first searched for in the image resource package of the corresponding resolution in the running memory according to the priority order. If it is found, the image is used as the target image; if it is not found, the image with the corresponding name is then searched for in the basic resource package in the running memory as the target image.

[0025] Furthermore, when the priority order of the basic resource package is set to be higher than that of the image resource package, the image with the corresponding name is first searched for in the basic resource package in the running memory according to the priority order, and it is determined whether the image is of size n*n. If so, the image with the corresponding name is then searched for in the image resource package of the corresponding resolution in the running memory as the target image; otherwise, the image is used as the target image, and there is no need to search in the image resource package again.

[0026] Furthermore, step 6 is preceded by:

[0027] Step 61: When creating an Android interface, parse the various attributes of the layout file under the Android interface, find the name of the image to be used based on the attribute, and then start searching based on the name of the image.

[0028] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described above for adapting Android application packages to different devices.

[0029] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described above for adapting Android application packages to different devices.

[0030] By adopting the above technical solution, the present invention has the following beneficial effects compared with the prior art: It separates the general basic resource package that does not require resolution adaptation and the image resource package that does require resolution adaptation into separate packages. The application package only stores the basic resource package (including general basic images and logo images that do not require resolution adaptation, and the image size is very small), eliminating the need to store multiple sets of image resource packages requiring resolution adaptation with large amounts of data. This can greatly reduce the size of the application package, reducing it by up to 50% or more.

[0031] The image resource package adapted to the device's screen resolution is downloaded and loaded when the application is first run, rather than being downloaded along with the application package. This ensures that devices with corresponding resolutions (phone screens) only load the image resource package adapted to their own resolution, avoiding the downloading of a bunch of useless image resource packages needed for other screen resolution adaptations. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0033] Figure 1 This is a flowchart of a method provided in an embodiment of the present invention.

[0034] Figure 2 This is a schematic diagram of an electronic device provided in an embodiment of the present invention.

[0035] Figure 3 This is a schematic diagram of a computer-readable storage medium provided in an embodiment of the present invention. Detailed Implementation

[0036] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be particularly noted that the following embodiments are for illustrative purposes only and do not limit the scope of the invention. Similarly, the following embodiments are only some, not all, embodiments of the present invention, and all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0037] This invention provides a method for adapting Android application packages to different devices, which can greatly reduce the size of the application package and avoid downloading image resource packages that are incompatible with the device resolution.

[0038] Example 1

[0039] Please see Figure 1 The method for adapting Android application packages to different devices in this invention includes the following steps:

[0040] Step 1: Create a basic resource pack and image resource packs at different resolutions;

[0041] In this embodiment, step 1 specifically includes:

[0042] Step 11: Create a basic resource package. The basic resource package contains a plurality of images with different names, such as: an image named A.png, an image named B.png, an image named C.png, and an image named D.png.

[0043] Step 12: Determine whether each image needs to be adapted to different resolutions. If so, modify the image to an n*n size identifier image and proceed to Step 13; otherwise, use the image as the base image and do not make any modifications.

[0044] For example, we sequentially evaluate each image. First, we evaluate the image named A.png. Since A.png is suitable for screens of different resolutions and has no resolution requirement, it can be considered the base image and no modifications are needed. Next, we evaluate the image named B.png. Since B.png needs to be used on screens of different resolutions and has resolution requirements, it can be considered the identifier image. We then resize this image to n*n, where n is an integer between 1 and 5. The smaller n is, the less memory it occupies; therefore, n=1 is preferred. Similarly, we evaluate the images named C.png and D.png. C.png is the base image, and D.png is the identifier image. Further details are omitted here.

[0045] Since the base image (such as A.png) is exactly the same in image resource packages of different resolutions, we can store A.png directly in the base resource package, thus avoiding the need for A.png to exist in image resource packages of different resolutions.

[0046] The images (such as B.png) are different in different image resource packages with different resolutions. Therefore, we need to store the corresponding B.png images in different image resource packages with different resolutions, and at the same time store a B.png image of any size (1*1, which has very little memory) in the basic resource package (required by the Android mechanism for packaging).

[0047] Step 13: Create image resource packages of different resolutions. Based on the name and quantity of each of the identified images, store supplementary images of the corresponding resolution with the same name and quantity as the identified images in the image resource packages of different resolutions.

[0048] For example, there are thousands of Android phone resolutions. Here, we take six resolutions as an example, with resolution sizes of 800x480, 854x480, 960x540, 1184x720, 1280x720, and 1920x1080. The two identified images in step 12 are named B.png and D.png. Therefore, the corresponding images named B.png and D.png are stored in the image resource packages for the six resolutions as supplementary images in the image resource packages.

[0049] Supplementary images have the same resolution as the corresponding image resource package. Multiple supplementary images within an image resource package have the same resolution. Supplementary images are a supplementary form of identification images, and the number of supplementary images in an image resource package corresponds one-to-one with the name and number of identification images in the basic resource package.

[0050] Step 2: Package the basic resource package and the identification code into an application package; the identification code is to quickly identify the resolution of the target device, thereby determining which resolution of the image resource package needs to be downloaded; by packaging the smaller basic resource package into the application package, and not packaging it together with the larger image resource package, the size of the application package can be greatly reduced.

[0051] In this embodiment, step 2 is followed by:

[0052] Step 21: Package the image resource packages of different resolutions separately and store them in the background.

[0053] Step 3: Install the application package. Upon first launch of the application, the target device's resolution is identified based on the identification code, and the corresponding image resource package is remotely downloaded from the background. Only the image resource package with a compatible resolution needs to be downloaded, without downloading the image resource package with an incompatible resolution, which greatly frees up memory and improves download efficiency.

[0054] For example, if the current phone resolution is 800*480, then we only need the images named B.png and D.png from the 800*480 resolution image resource package. The images named B.png and D.png from the other image resource packages are not actually needed. Therefore, we can download only the image resource packages that are useful.

[0055] Step 4: Load the basic resource package and the downloaded image resource package from the application package into the runtime memory; when obtaining images, they need to be extracted from the runtime memory, therefore, the images in the basic resource package and the image resource package need to be loaded into the runtime memory.

[0056] In this embodiment, step 4 specifically includes:

[0057] Step 41: When the application is launched, the Android system automatically loads the basic resource package in the application package into the running memory by default;

[0058] Step 42: Create a resource object and load the downloaded image resource package into the runtime memory through the resource object.

[0059] Step 5: Take over the creation of the Android interface through the interface controller and configure the image acquisition method for this Android interface. Android interfaces generally have two forms: Activity and Fragment. You can manage either type of Android interface by using the `getLayoutInflater().setFactory2()` method to replace the default `LayoutInflater.Factory2` method in the Android system. This way, you can take over the creation of the installation interface, and all elements within the installation interface become controllable. At this point, you can configure the image acquisition method for this Android interface.

[0060] In this embodiment, the priority order of the image resource package is set to be higher than that of the basic resource package.

[0061] Step 6: Obtain the target image from the running memory according to the image acquisition method.

[0062] In this embodiment, step 6 specifically involves: when creating an Android interface, parsing the various attributes of the layout file under the Android interface, finding the name of the image to be used based on the attributes, and then starting the search based on the image name; when the priority order of the image resource package is set to be greater than that of the basic resource package, the image with the corresponding name is searched first from the image resource package of the corresponding resolution in the running memory according to the priority order. If it is found, the image is used as the target image, loaded, and applied to the correct position according to the attributes; if it is not found, the image with the corresponding name is searched from the basic resource package in the running memory as the target image, loaded, and applied to the correct position according to the attributes.

[0063] For example, if the parsed attributes include the need to use an image named A.png at the top of the Android interface, due to the priority order, the search for the image named A.png will first be conducted in the image resource package corresponding to the resolution. Since the image named A.png is a base image and cannot be found in the image resource package, the search will then be conducted in the base resource package. Once the corresponding target image is found, the target image will be loaded and applied to the top of the Android interface.

[0064] The parsed attributes also include the need to use an image named B.png in the center of the Android interface. Due to the priority order, the image named B.png is first searched in the image resource package at the corresponding resolution. Since the image named B.png is not a base image, it can be found in the image resource package. Therefore, the corresponding target image is found, and the target image is loaded and applied to the center of the Android interface.

[0065] Example 2

[0066] The difference between Example 2 and Example 1 is as follows:

[0067] Step 5: Take over the creation of the Android interface through the interface controller and configure the method of obtaining images under the Android interface; in this embodiment, the priority order of the basic resource package is set to be greater than that of the image resource package.

[0068] Step 6: Obtain the target image from the running memory according to the image acquisition method.

[0069] In this embodiment, step 6 specifically involves: when creating an Android interface, parsing the various attributes of the layout file under the Android interface, finding the name of the image to be used based on the attributes, and then starting the search based on the image name; when the priority order of the basic resource package is set to be greater than that of the image resource package, the image with the corresponding name is searched first from the basic resource package in the running memory according to the priority order, and it is determined whether the image is n*n in size. If so, the image with the corresponding name is searched from the image resource package of the corresponding resolution in the running memory as the target image, the target image is loaded and applied to the correct position according to the attributes; if not, the image is used as the target image, the target image is loaded and applied to the correct position according to the attributes, without needing to search from the image resource package again.

[0070] For example, if the parsed attributes include the need to use an image named A.png at the top of the Android interface, due to the priority order, the search for an image named A.png will be conducted first in the basic resource package. Since the image named A.png is a basic image and can be found in the basic resource package, the corresponding target image will be found, and the target image will be loaded and applied to the top of the Android interface.

[0071] The parsed attributes also include the need to use an image named B.png in the center of the Android interface. Due to the priority order, the search for an image named B.png is first performed in the basic resource package. Since the image named B.png is not a basic image, it cannot be found in the basic resource package. Then, the search for an image named B.png in the image resource package corresponding to the resolution is performed. If it can be found in the image resource package, the corresponding target image is found, and the target image is loaded and applied to the center of the Android interface.

[0072] Example 3

[0073] The difference between Example 3 and Example 1 is as follows:

[0074] Step 5: Take over the creation of the Android interface through the interface controller and configure the method of obtaining images under the Android interface; in this embodiment, the basic resource package and the image resource package are set to search for images simultaneously.

[0075] Step 6: Obtain the target image from the running memory according to the image acquisition method.

[0076] In this embodiment, step 6 specifically involves: when creating an Android interface, parsing the various attributes of the layout file under the Android interface, finding the name of the image to be used based on the attributes, and then starting a search based on the image name; simultaneously searching for the corresponding image name from the basic resource package and image resource package in the running memory; if only one image with the corresponding name is found, then that image is used as the target image, loaded, and applied to the correct position according to the attributes; if two images with the corresponding name are found, determining whether their size is n*n based on the size of these two images; if so, it means that the image is a basic image and is abandoned from loading; if not, it means that the image is not a basic image, then that image is used as the target image, loaded, and applied to the correct position according to the attributes.

[0077] For example, if the parsed attributes include the need to use an image named A.png at the top of the Android interface, since both the basic resource package and the image resource package can search for images simultaneously, the search will be conducted in both packages to find an image named A.png. Since the image named A.png is a basic image, it can be found in the basic resource package but not in the image resource package. Only one image named A.png will be found, and this image will be the target image. Therefore, the target image will be loaded and applied to the top of the Android interface.

[0078] The parsed attributes also include the need to use an image named B.png in the center of the Android interface. Since the basic resource package and the image resource package can search for images simultaneously, the search is conducted in both packages. Because the image named B.png is not a basic image, it can be found in both the basic resource package and the image resource package corresponding to the resolution. The image size is then determined. The size of the image named B.png in the basic resource package is n*n, while the size of the image named B.png in the image resource package is not n*n. Therefore, the image named B.png in the image resource package is selected as the target image, and this target image is loaded and applied to the center of the Android interface.

[0079] like Figure 2 As shown, this embodiment of the invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the above-described method for adapting application packages for different devices based on Android.

[0080] like Figure 3 As shown, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method for adapting Android application packages to different devices.

[0081] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0082] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0083] The above description is only a part of the embodiments of the present invention and does not limit the scope of protection of the present invention. Any equivalent device or equivalent process transformation made based on the content of the present invention specification and drawings, or direct or indirect application in other related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for adapting Android application packages to different devices, characterized in that, Includes the following steps: Step 1: Create a basic resource pack and image resource packs at different resolutions; specifically including: Step 11: Create a basic resource package, which contains a plurality of images with different names; Step 12: Determine whether each image needs to be adapted to different resolutions. If so, modify the image to an n*n size identifier image and proceed to Step 13; otherwise, use the image as the base image and do not make any modifications. Step 13: Create image resource packages of different resolutions. Based on the name and quantity of each of the identified images, store supplementary images of the corresponding resolution with the same name and quantity as the identified images in the image resource packages of different resolutions. Step 2: Package the basic resource package and identification code into an application package; Step 3: Install the application package. When the application is launched for the first time, the resolution corresponding to the target device is identified according to the identification code, and the image resource package of the corresponding resolution is downloaded. Step 4: Load the basic resource package and the downloaded image resource package from the application package into the runtime memory; Step 5: Take over the creation of the Android interface through the interface controller and configure the method of obtaining images under the Android interface; wherein, the configuration of the method of obtaining images under the Android interface specifically means: setting the priority order of the image resource package to be greater than that of the basic resource package, or setting the priority order of the basic resource package to be greater than that of the image resource package. When the priority order of the image resource pack is set to be higher than that of the basic resource pack, the image with the corresponding name is first searched for in the image resource pack of the corresponding resolution in the running memory according to the priority order. If it is found, the image is used as the target image; if it is not found, the image with the corresponding name is then searched for in the basic resource pack in the running memory as the target image. When the priority order of the basic resource package is set to be higher than that of the image resource package, the image with the corresponding name is first searched for in the basic resource package in the running memory according to the priority order. It is then determined whether the image is of size n*n. If so, the image with the corresponding name is then searched for in the image resource package of the corresponding resolution in the running memory as the target image. If not, the image is used as the target image, and there is no need to search in the image resource package again. Step 6: Obtain the target image from the running memory according to the image acquisition method.

2. The method for adapting Android application packages to different devices as described in claim 1, characterized in that, Step 2 is followed by: Step 21: Package the image resource packages of different resolutions separately and store them in the background.

3. The method for adapting Android application packages to different devices as described in claim 1, characterized in that, Step 4 specifically includes: Step 41: When the application is launched, the Android system automatically loads the basic resource package in the application package into the running memory by default; Step 42: Create a resource object and load the downloaded image resource package into the runtime memory through the resource object.

4. The method for adapting Android application packages to different devices as described in claim 1, characterized in that, The process preceding step 6 also includes: Step 61: When creating an Android interface, parse the various attributes of the layout file under the Android interface, find the name of the image to be used based on the attribute, and then start searching based on the name of the image.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method for adapting Android application packages to different devices as described in any one of claims 1 to 4.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by the processor, the program implements the method for adapting Android application packages to different devices as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Application, application installation resource processing method, server and terminal device

    CN107515763A

  • Application starting method and device and electronic equipment

    CN111176747A