Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResourceBundle on Android in Assets folder

i´m currently useing ResourceBundles in a pure Java program. Now I want to use the same files inside of an Android app. It works as intended, when the file is placed e.g. at /sdcard/. Is there a way to load them directly from the known android folder structure? e.g. from assets wihtout manually coping them to the sdcard?

This works at the sdcard:

    File file = new File("/sdcard/");
    URL[] urls = new URL[0];
    try {
       urls = new URL[]{file.toURI().toURL()};

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    ClassLoader loader = new URLClassLoader(urls);
    ResourceBundle rb = ResourceBundle.getBundle("test", Locale.DEFAULT, loader);

This url doesn´t work for the assests folder:

   urls = new URL[]{new URL("file:///android_asset/test/")};

Thanks for any help.

like image 873
user2479595 Avatar asked Nov 09 '22 23:11

user2479595


1 Answers

Try creating a resources folder on this path src/main/resources and then put or get your files from there by using ResourceBundle on Android.

It works for me.

like image 70
efkan Avatar answered Nov 15 '22 11:11

efkan