how can i write to a file and read from it in android studio? - Android Developer Previews

hi always use c and c++ but now i'm trying to create a game application with ndk
but it needs some java codes and i dont know java at all!!
i want to create a file
write a string in that file
then read that string again from that file?
can you help me? or show me a way to do that?!

mjs2001227 said:
write a string in that file
then read that string again from that file?
Click to expand...
Click to collapse
Write String to File in Java - TutorialKart
To write String to File in Java, there are many processes we can follow. Some of them are using FileUtils class of apache's commons.io library, Input Streams, etc.
www.tutorialkart.com
good luck!

Related

[QQ] Save textfile on SD

Hello devs.
I have a quick request for some skilled developer in Eclipse,how to save strings to SD card as a text file? I am noobie in Java development,so if someone is so friendly to provide me some source code of the solution,I'll be very grateful for it.
All I want is to create a simple program,which will save string from editbox to a file and it is appended to previous lines,already saved before. All other things I am able to do myself.
Please try out this program,that creates 'append.txt' file for imagination of my request.
Thanks all for your help in advance.
Here is my source in Delphi:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var f:textfile;
const fi:string='append.txt';
begin
assignfile(f,fi);
if(fileexists(fi))then append(f) else rewrite(f);
writeln(f,edit1.text);
closefile(f);
end;

[HELP] Passing a String to getString

hello everybody!
i'm making a program that needs to set to a textview the content of a string stored in resource/string file
in my program i generate a string and i need to set the text using that string like a resource id. the problem is that the resouurce ids are integers.
something like:
test = (TextView) findViewById(R.id.tvMyTV);
mystring = "test_a";
test.setText(Html.fromHtml(getString(R.string.mystring)));
-----------
i obviously can't use R.string.mystring, i should use
test.setText(Html.fromHtml(getString(R.string.test_a)));
somebody have a solution to this problem?
thank you all and sorry for my bad english. i'm italian
Hi!
Why are you using HTML.fromHTML? You don't need to use that to set a string from your resource.
This is how it works. Your resource ids are ints. you pass this int to some methods which get you the respective resource. The getString method similarly takes an int resource id for your string and returns you a string which you just set to a textview
Code:
String myString = getString(R.string.mystring);
test.setText(myString);
or simply
Code:
test.setText(getString(R.string.mystring));
Thats all there is to it
thank you for the fast answer but it doesnt work
i'm using Html.fromHtml because the string is html-formatted (inside have <b>...</b> , <br/>)
Code:
String myString = getString(R.string.mystring);
R.string.mystring doesnt exist besause mystring dont exist as a resource string (which have an associated Int id). mystring is a variable.
i have to write something like
Code:
String myString = getString(R.string.[the content of mysting]);
i tried to write
Code:
test.setText(pleaseGiveMeMyString(mystring));
where
Code:
public String pleaseGiveMeMyString(String inputstring) {
// TODO Auto-generated method stub
String outputString = "R.string." + inputstring;
return outputString;
}
but in the textView i read R.string.test_a not the content of the string test_a
like i wrote
Code:
test.setText("R.string.test_a");
There is a lot that is wrong with what you are trying to do. You are trying to set the output of an HTML code to a TextView. It won't work.
If you want to display the output of an HTML code you should use a WebView.
I am afraid I am having a hard time understanding what exactly you are trying to do with the string resources but I'm going to try to explain this to you again.
This is how you set a string in strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test_string">This is my string</string>
</resources>
Then in your java program you get the string like this
Code:
String mystring = getString(R.string.test_string);
the contents of mystring are "This is my string"
Besides I am not sure if it is a wise thing to store HTML code as part of your strings.xml file. Because of the similarities in HTML and XML tag formats.
You'd be better off making a .html file in notepad or something and then just put this .html file in the raw folder of your project. Then you just load this file using getResources().openRawResources(). Then use the InputStream object this method ouputs to create a BufferedReader and read in the HTML as a String.
Pass this string to a WebView to display your HTML in a renderered form.

Eclipse Question

I'm in the process of figuring out how to develop for android...and I'm trying to add an EditText field but I get and error. Looking at the graphical layout, the screen fades out. Is there a reason this would happen.
I am also getting an error that says "Failed to load properties file for android project".
Any help is welcomed.
Thanks in advance.
ok
jacari91 said:
I'm in the process of figuring out how to develop for android...and I'm trying to add an EditText field but I get and error. Looking at the graphical layout, the screen fades out. Is there a reason this would happen.
I am also getting an error that says "Failed to load properties file for android project".
Any help is welcomed.
Thanks in advance.
Click to expand...
Click to collapse
if you what to write something on a button on your app screen,,,, it's not directly done for android
so you have to go to a "Value" folder of your project and u will find a "string.xml " file
here you can add what ever text you want to use it on your app screen where ever you wanna
1- click on string file and you will see an interface and an add button
2- click on add button -> select string
3- now you have to enter a string NAME and string Value
4- string NAME is an ID of this string
5- string Value is an Value that you can use it on your app screen
NOW save your project
and go to main.xml
right click on button -> edit text
and you will see add ID's that you interned in string .xml
<<<<this is used for managing app's that have Multi Languages :good:>>>>
click on THANKS button if you find it helpful
osama_m2s said:
if you what to write something on a button on your app screen,,,, it's not directly done for android
so you have to go to a "Value" folder of your project and u will find a "string.xml " file
here you can add what ever text you want to use it on your app screen where ever you wanna
1- click on string file and you will see an interface and an add button
2- click on add button -> select string
3- now you have to enter a string NAME and string Value
4- string NAME is an ID of this string
5- string Value is an Value that you can use it on your app screen
NOW save your project
and go to main.xml
right click on button -> edit text
and you will see add ID's that you interned in string .xml
<<<<this is used for managing app's that have Multi Languages :good:>>>>
click on THANKS button if you find it helpful
Click to expand...
Click to collapse
Thanks. Let's say I'm making a to-do app...would this allow me to make an area where the user would enter their task?

C++ and APK files

I am using NDK with the Android 2.2 SDK. I want to use C++ commands to access the file system in my application's APK.
1. Is there a way to access the APK file contents directly with C++? I want to read directories and files just like on a PC.
2. If not, is there a way to distribute apps in Google Play, in a way so that C++ can read our application's files?
Try "getenv( "HOME" );" to get "<installed apk path>/files". Then you can access that with opendir(), readdir(), closedir() and access files with open(), fopen(), close(), fclose(), etc.
Nice, I will try this out today!
getenv("HOME") returns NULL in my application.
Ahh. I was testing with necessitas. It looks like they do "m_activity.getFilesDir().getAbsolutePath()" in their java code and pass that string to the c++ code. And then the c++ uses putenv() to set the path as $HOME. Thats why it worked for me.
It looks like you might have to use some similar magic to pass in the path from your java to your c++. There may be a function in the JNI to get that directory, but I haven't looked for it.
Questions should be posted in Q&A forums, not Development forums.
http://forum.xda-developers.com/announcement.php?a=81
See rule #15
Thread moved.
I found out how to locate the APK file path in Java. Then I pass this to C++ and load the APK file (it's just a ZIP file with a different extension).

[Q] password.key decription

!!! Discussion is for educational purpose only !!!
As we know, Android stores Lockscreen's Pin and Password in data/system/password.key
In this file appears an alphanumeric string (probably an hex string which refer to other databases).
I've made a research, but I didn't find if it's possible to know the Lockscreen's password/pin starting with this file.
Any idea?
Can anyone try to explain how does it work?

Categories

Resources