资产文件夹中的更新图像未在启动应用程序上显示

时间:2022-03-19 06:41:23

is it possible to update assets folder on every update of app.I make a quiz app and it has images on assets folder.Number of images on folder shows when i launch the app.But when i update images on assets folder say from 10-20 images the actual total number of images to be shown on app is 20 but i still see 10 images.But when i uninstall and install app i do see all 20 images.how to updated assets folder without uninstalling app?

是否有可能在app的每次更新时更新资产文件夹。我做一个测验应用程序,它有资产文件夹上的图像。当我启动应用程序时,文件夹上的图像数量显示。但是当我更新资产文件夹上的图像时,请说10- 20个图像在应用程序上显示的实际图像总数是20但我仍然看到10个图像。但是当我卸载并安装应用程序时,我确实看到所有20个图像。如何更新资产文件夹而不卸载应用程序?

String[] getImagesFromAssets() {
    String[] img_files = null;

    try {
        img_files = getAssets().list("pictures");
    } catch (IOException ex) {
        Logger.getLogger(GameActivity.class
                .getName()).log(Level.SEVERE, null, ex);
    }
    return img_files;
}

void loadImage(String name) {
    try {
        InputStream ims = getAssets().open("pictures/" + name);

        Drawable d = Drawable.createFromStream(ims, null);
        image.setImageDrawable(d);

    } catch (IOException ex) {
        return;
    }
}

2 个解决方案

#1


2  

AFAIK Assets folder of android application will be initialized once at the time of installation only. You cannot update the assets folder after the application has been packaged and installed. After installation if you do any changes in the resources it will not reflect to your older installed version.As Asset folder is read only , you cannot write or update any file present there.

Android应用程序的AFAIK Assets文件夹仅在安装时初始化一次。打包并安装应用程序后,无法更新assets文件夹。安装后如果您对资源进行任何更改,它将不会反映到您的旧版本。由于Asset文件夹是只读的,您无法编写或更新其中存在的任何文件。

If you want to update it then you need to uninstall the older version and install new version.

如果要更新它,则需要卸载旧版本并安装新版本。

#2


0  

You can use this to take image from assets:

您可以使用它从资产中获取图像:

AssetManager assetManager = getAssets();
            InputStream istr = null;
            try {
                istr = assetManager.open(strName);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Bitmap bitmap = BitmapFactory.decodeStream(istr);

#1


2  

AFAIK Assets folder of android application will be initialized once at the time of installation only. You cannot update the assets folder after the application has been packaged and installed. After installation if you do any changes in the resources it will not reflect to your older installed version.As Asset folder is read only , you cannot write or update any file present there.

Android应用程序的AFAIK Assets文件夹仅在安装时初始化一次。打包并安装应用程序后,无法更新assets文件夹。安装后如果您对资源进行任何更改,它将不会反映到您的旧版本。由于Asset文件夹是只读的,您无法编写或更新其中存在的任何文件。

If you want to update it then you need to uninstall the older version and install new version.

如果要更新它,则需要卸载旧版本并安装新版本。

#2


0  

You can use this to take image from assets:

您可以使用它从资产中获取图像:

AssetManager assetManager = getAssets();
            InputStream istr = null;
            try {
                istr = assetManager.open(strName);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Bitmap bitmap = BitmapFactory.decodeStream(istr);