Weird, I dropped a settings.xml in res/xml in a quick test project and
R.xml.class.getDeclaredFields() worked just fine. I tried running from
Eclipse and also exporting to an APK, installing, and running that -
both worked. Tested on an Android 1.6 G1 phone and an Android 2.1
emulator. Maybe there are different ways to build that actually do
strip them out?

Screenshot:
http://imgur.com/yWU3I.png

Code ( http://pastebin.com/f4f1ee8bd ):
public class TestReflectionOnR extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView text = (TextView) findViewById(R.id.text_view);
        text.append("field count: " + R.xml.class.getDeclaredFields
().length + "\n");
        for (Field f : R.xml.class.getDeclaredFields()) {
            f.setAccessible(true);
            try {
                text.append(f.getName() + ": " + f.get(null) + "\n");
                        } catch (IllegalArgumentException e) {
                                throw new RuntimeException(e);
                        } catch (IllegalAccessException e) {
                                throw new RuntimeException(e);
                        }
        }
    }
}


On Feb 1, 6:19 pm, Nathan <[email protected]> wrote:
> How does one go about listing the resources that are available in an
> application?
>
> For example, I would want to find the names of all files under /res/
> xml.
>
> Reflection on the R class didn't seem to work since the identifiers
> are static constants. R.xml.class.getDeclaredFields() doesn't return
> any fields.
>
> The AssetManager didn't seem to work either because these are not raw
> assets.
>
> Does anyone have ideas or examples?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to