开发者

Configuring Android application from file

I am trying to create an Android application that would use a configuration file (plain text) when loading.

When testing locally (with an emulator), I place my config file in the src/ folder (ecplise) and I see it is copied and used from the bin/ folder upon project build.

My questions are:

1) Where do I need to place this file when testing on a device ? From what I understand I need the *.apk file and the config file to be both present on the device during run t开发者_JS百科ime.

2) If I am using eclipse to install the *.apk file can I somehow specify the config file as a dependant file and force eclipse to copy it as well ? If not do I need to manually copy the *.apk & config files to the device ?

NOTE: I am using getResourceAsStream to load the file.

Thanks,

RM


Well actually there shouldn't be any problems with accessing the file in a way you do. But preferred (and recommended by Android developers) way is to place the file into /res/raw folder. Then you can access the file as application resource:

InputStream is = getResources().openRawResource(R.id.your_file_name);

Here getResources is a method of Context class, it should accessible anywhere within your activities. R.id.your_file_name is a static field generated by eclipse at the time you place your file into /res/raw folder.

Read the https://developer.android.com/guide/topics/resources/index.html to get more about application resources at Android.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜