How To Extract XML Strings From an Android App's Data - android

I have an app that pulls an XML file from a URL and saves it to its data/data/package.name/file.xml directory. All the XML is is strings. Say I want to reference the String named "restaurant1PhoneNumber". How do I extract it's string value in the XML file?

Related

Show all .txt files from a folder in an activity

I have a application where the user can write a text into a EditText and the written text is saved in an auto generated .txt file.
Now I want to show all the txt files from the folder in an activity, not like a regular file browser, just the title of the .txt files in a ListView or as a TextView (each file is illustrated as a TextView).
Get the path of that directory as string and create a new file with this path then,
String path=Environment.getExternalStorageDirectory().getAbsolutePath()+"..../yourFolder";
File file=new File(path);
or
File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"..../yourFolder");
Use file.list which will give u all files name in form of an array then use a for loop with endsWith function and store data into a list like this
String arr[]=file.list();
List l=new ArrayList<>();
for(String i:arr){
if(i.endsWith(".txt")){
l.add(i);
}
}
you will have names all text files under selected directory in list l
In Java 8 you can use Files API and Stream API
Files
.list(Paths.get("."))
.forEach(System.out::println);

Can .txt file be retrieved to textview from parse.com

Can I add .txt file in parse.com and retrieve it to my textview in my app. I know how to add a string and retrieve it but have a confusion regarding the .Txt file
When your creating your ParseFile object, you can give it a file type by adding the file extension to the end of the key name.
Eg:
ParseFile file = new ParseFile("sometext.txt", fileData);
will create a text file the the contents of fileData. This can be attached to a ParseObject and saved/retrieved from Parse the usual way.
By the way, you should give this question a parse.com tag.

Get string from xml (other than strings.xml)

I want to get a string array from other file than strings.xml, because I want my project to be organised.
For example, I have this code:
String[] column1 = getResources().getStringArray(R.array.column1);
But my string array isn't located in strings.xml, but in \res\values\tables\10.xml
How can I get the string array from that file?
Thanks in advance.
Your XML files can have arbitrary names, but they need to be located in the values folder. I suggest just calling your file tables10.xml.

Constants in Android xml file

I have some code like this in my Android settings xml file (res/xml/settings.xml):
<EditTextPreference
android:title="#string/settings_date_format"
android:summary="#string/settings_date_format_summary"
android:key="settingsDateFormat"
android:defaultValue="#string/config_settings_date_format_default_value" />
And a string like this:
<string name="config_settings_date_format_default_value">dd MMM yyyy, HH:mm</string>
As you can see, I'm setting the default value to a string. However, I'd like to have these default values stored somewhere else as it doesn't make sense to put them in res/values/strings.xml
Is it possible for me to put them in a new file called "config.xml" for example?
You can just add another XML file in the values folder and name it however you want.
On compilation time, the compiler will scan all your resources folders, regardless of the files and their names, and will create a lookup table for all your resources.
You can have multiple files with string constants in them. You just have to follow the file naming rules and make sure not to duplicate any of the string or file names.

Store .txt filenames in array on Android

I would like to store only .txt filenames from a specific dir (let's say: /sdcard/docs/) into an String array.
Example:
In /sdcard/docs/ there are 5 files: foo.txt, bar.jpg, foofoo.txt, loool.png and foobar.txt. I would like to get array with contents: "foo.txt", "foofoo.txt", "foobar.txt"
How could I do it?
List all files:
https://developer.android.com/reference/java/io/File.html#list%28%29
or
List with filter:
https://developer.android.com/reference/java/io/File.html#list%28java.io.FilenameFilter%29
Just pass your path to the File constructor, and call one of the above methods on it.

Categories

Resources