we have a text file stored on our server where I work, and I have searched on how to read in a specific line from that text file and have it display on the screen of my Android activity... but I haven't found a solution yet. Only two words, or so, of the text in the file on the server will be changed/replaced periodically, and I would like those changes to take effect/be updated in my Android app each time. Not sure why I couldn't find an answer to this yet. Any help is much appreciated! Thank you!
Asked
Active
Viewed 218 times
1 Answers
0
Actually the best way to have a secure transaction between an android app and server is to use web service like JSON
. You request something from your android app to server, Then in server request will be analyse and response to your android app. You can send some request that tell the server what to do. Then in server side have a script that do your job and send response to your android app.
-
Hmmm... I've found lots of information about JSON, but I must not be grasping it completely. I really only need to read in one single line from a file on our server (and it's the only line in the file). That's all. I just can't seem to figure it out so far. I will keep searching and trying code until my fingers bleed. So any additional help would be greatly appreciated in the meantime! – LargeGlasses Aug 31 '12 at 20:31
-
I think you have another choice. You can use http post request. You can post some data like html form post, then server do its job and response to your android app. It's good to see http://strife.pl/2011/12/android-how-to-send-request-post-to-the-server-full-application/ and http://androidsnips.blogspot.ca/2010/08/send-request-to-server-and-read.html. – Aug 31 '12 at 20:46
-
Wahooo!! I've almost got it!! The second link you shared was most helpful. Now, my line is being received from the server successfully, but it's displaying as a Toast. I really would like it to just display in the activity as a TextView. How can I achieve this?? (Thanks in advance! Your help is outstanding!) – LargeGlasses Aug 31 '12 at 21:26
-
Actually, I figured it out!! All I had to do was connect my TextView variable with the xml, and then: myTextViewVar.setText(response); //response is the readIn var Thank you so much for your direction!! – LargeGlasses Aug 31 '12 at 21:49
-
If you want to set the text in `TextView`, You can create a `TextView` in your activity, Then set the text in `TextView`. This link may help you http://stackoverflow.com/questions/2300169/how-to-change-text-in-android-textview. I'm so happy to help you. – Aug 31 '12 at 21:51
-
Hey, sorry, I have another question. I'm curious, how would I read in multiple lines from the server into my TextView instead of just one line? – LargeGlasses Aug 31 '12 at 22:08
-
If you want to read multiple line from a file, You must know that each line separate by new line `\n`. So, You can get new line text by detecting that is there any `\n` or not? See this link: http://www.velocityreviews.com/forums/t138912-reading-lines-from-a-text-file-using-the-bufferedreader-class.html it shows everything. I hope that link help you. – Aug 31 '12 at 23:39
-
Not quite. I couldn't get it to work.... It should be a simple solution, but I haven't figured it out yet. And I actually won't be able to work on this project again until Tuesday September 4th... so I'll see what i can do on Tuesday! Thanks for your help so far! Talk to you soon! – LargeGlasses Sep 01 '12 at 01:11
-
Hi, I still have not solved the second issue. I wasn't able to get much help from the last link you sent me. I'm still trying though. Any other suggestions? – LargeGlasses Sep 04 '12 at 23:52
-
Hi. Try to read this link: http://stackoverflow.com/questions/2296685/how-to-read-input-with-multiple-lines-in-java maybe it can help you? If you couldn't solve the problem by this link, explain more detail that what do you want exactly. – Sep 05 '12 at 12:32
-
Hi, sorry I did not respond for a long time. I got my problem solved. I created an external xml file, and it reads the lines in from that. However, now I'm trying to add tabs at the top of my app that correspond to each activity that I have... this is the most difficult so far. – LargeGlasses Sep 13 '12 at 19:34
-
Hi :D Actually there is a lot of way to create tab (Slide Tab, Vertical Tab, Horizontal Tab and ...). First, you must make decision which style do you want? And my suggestion is ask new question in this site. It can help you. But I'm here to help you :) – Sep 13 '12 at 20:07
-
Hey, I have posted a new question. Here is the link http://stackoverflow.com/q/12432410/1637401 – LargeGlasses Sep 14 '12 at 21:50