java http to pull website data - Java for Android App Development

hello guys
i am having trouble understanding how such apps work and what i need to start developing one
i've learned that you can pull website information using it's API in JSON format and display it
but if the website does not provide an API is possible to get the JSON data of any website? is it done through http request ?
i was also trying to connect my application to several news websites that keeps posting news update is it possible to read the information each time it is updated ?
and what should i know besides java to be able to connect my app to any website get information from this website and display the result regarding if it has an API or not
example : connect to a news website pull the newly posted news and display it or connect to a gaming website get the top 10 games and display them
thank you for your help

ghattas.akkad said:
hello guys
i am having trouble understanding how such apps work and what i need to start developing one
i've learned that you can pull website information using it's API in JSON format and display it
but if the website does not provide an API is possible to get the JSON data of any website? is it done through http request ?
i was also trying to connect my application to several news websites that keeps posting news update is it possible to read the information each time it is updated ?
and what should i know besides java to be able to connect my app to any website get information from this website and display the result regarding if it has an API or not
example : connect to a news website pull the newly posted news and display it or connect to a gaming website get the top 10 games and display them
thank you for your help
Click to expand...
Click to collapse
If the site you're scraping doesn't provide JSON then you can query the site using HTTP. Something like this.
Code:
URL url = new URL(target);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(connection.getInputStream());

laidlow said:
If the site you're scraping doesn't provide JSON then you can query the site using HTTP. Something like this.
Code:
URL url = new URL(target);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(connection.getInputStream());
Click to expand...
Click to collapse
thank youu
html parsing is very annoying especially when dealing with a lot of websites in a single app
i was looking for an easier method in which i can access the websites databases pull data and post it but i think if they dont have an API for that they wont give me that permission

ghattas.akkad said:
thank youu
html parsing is very annoying especially when dealing with a lot of websites in a single app
i was looking for an easier method in which i can access the websites databases pull data and post it but i think if they dont have an API for that they wont give me that permission
Click to expand...
Click to collapse
If you want an awesome library that helps you using http requests, take a look at Volley, which is really easy to use on all API levels. I didn't raed through it, but to me it sounds like you want to have some kind of RSS reader functionaly, take a look at this tutorial for instance.

Related

HTTP Server on WM6

Hi Guys!
I'd like to create a webserver on wm6 so I can contact to Localhost (127.0.0.1) to retrieve Phone info.
Purpose is a Flash app which uses GPS and Camera (Those or not accessable with actionscript)
I want the server to put GPS and Camera information on the localhost.
I know Freestyl (aka WhoNeedsAnIphone) uses a http server to pass some device variables to their flash app. But the project stopt and no code was released.
For Nokia Phone there's a Tool called KuneriLite to acces phone info with Flash.
I Also found Depeche But I don't really understand it....
Any Help/Code/App is welcome.
Jeff
Hi, take a look here: http://goahead.com/products/webserver/download.aspx
I played around with it some time ago.
It has a lot of features like cgi and so on.
Nice Solution....
It Works but im more into C# then C++..
Is there a C# solution for this?
All help is welcome
Depending on how many of the HTTP verbs you really need to support (ie, do you just want to respond to a HTTP get for a certain url?) you could knock up a simple HTTP server in C# in an hour or two tops.
There's tonnes of examples of simple HTTP servers in C# on the web...
Sounds good,
But i'm only able to find C# webservers for PC, not for windows mobile...
The only thing the server has to do is respond from the code, so i dont have to load actual ASP/HTML pages...
Just a listener on Localhost, if i request localhost/req?GetVar=Cam
I can do something like WriteRespone("Cam=" + SomeSysVar)
Here you go
Attached is a C# simple http server application that I knocked up based on the MSDN sample at http://msdn.microsoft.com/en-us/library/bb397809.aspx.
I've not tested it on a phone.
The sample is for the compact framework.
Should work without any hassle.
Complete source included and the simplest parsing possible (currently responds to a http GET request for / with a chunk of HTML with "1" as the body).
Good luck, have fun.
(Oh and I just noticed there's a confusingly commented out line that says "write response" in the source, remove / ignore it.)
You can test the windows app from a web browser by pointing at http://localhost:83
edit:
apologies, i meant to close another thread.
Thnx Alot
Found this solution: http://bansky.net/blog/2007/10/compact-web-server-in-compact-framework/
It Worked for me ;-)
That looks like a good general purpose solution
My example is tailored towards specific custom processing over HTTP rather than serving of files -> in the style of a RESTful API.
From the look of it you can do a similar thing with the Compact Web server by hooking up what the author labels a "Special file type" and adding your custom handling code in there.
[edit]
That said, you could actually edit my example to File.Open whatever was passed as a parameter off the disk and stream that back to the client, providing a more standard HTTP server without configuration.
Nice simple solution u've got!
I will try to get it to work the way i want,
lookin' @ the amount of code it should be a lot faster then my previous solution.
Just noticed a very small bug. I'm refactoring the code to be a little better engineered. I'll upload a new sample shortly (you may have already managed to make use of it).
Right, I've re-engineered the code a little.
While the example now isn't contained in a single file, the source is now far more logical, readable and maintainable.
You'll notice the code that actually deals with the request is now hidden away in the HttpVerbs namespace.
Basically if you look at the file HttpGet.cs there's a good working example of how to implement whatever behaviour you like based off of a HTTP Get request to the server.
Code's pretty decent now, slightly more ready for prime time than previously, generally more type-safe and doesn't rely on string parsing all over the place.
Enjoy.
Binary?
Can you please put here binary (exe file) for Windows Mobile 6.1?
Thanks

What Topic Do I Need To Tackle To Develop This Kind Of App?

The harvard university android app from google play store. (I can't seem to post any outside link yet for this account)
I want to create one for may school but I'm just starting to learn android programming, so guys I need your help on the topics that I need to study to create an app like that. I greatly appreciate any kind of comments. Cheers!
clonedaccnt said:
The harvard university android app from google play store. (I can't seem to post any outside link yet for this account)
I want to create one for may school but I'm just starting to learn android programming, so guys I need your help on the topics that I need to study to create an app like that. I greatly appreciate any kind of comments. Cheers!
Click to expand...
Click to collapse
Fragments, ListViews, JSON parsing (for communication with the web server to download news etc), Android SQLite databases (I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example), Google Cloud Messaging notifications, notifications, encryption.
There are lots more but these are some of the main ones. In addition I would not advise trying to copy the "look" or aesthetics of the Harvard application as it frankly looks disgusting, whoever designed that needs a course in UI design
any book suggestions?? im only studying at home and wanted to start studying android app development
m0nm0npalam0n said:
any book suggestions?? im only studying at home and wanted to start studying android app development
Click to expand...
Click to collapse
Android Application Development for Dummies and Learn Java for Android Development are 2 that I have in ebook form, though I can't say I've used them much as I don't really learn by reading books, more like looking at the source code of other apps and messing with it to see what happens
Android Application Development for Dummies goes through a wide range of topics including widgets, SQLite storage, possibly SharedPreferences (can't remember), ListView etc but does assume that you can at least follow what the sample code is doing - the sample code is commented but if you have not done any coding at all before then you probably should learn the basics of Java before reading it
Jonny said:
Android Application Development for Dummies and Learn Java for Android Development are 2 that I have in ebook form, though I can't say I've used them much as I don't really learn by reading books, more like looking at the source code of other apps and messing with it to see what happens
Android Application Development for Dummies goes through a wide range of topics including widgets, SQLite storage, possibly SharedPreferences (can't remember), ListView etc but does assume that you can at least follow what the sample code is doing - the sample code is commented but if you have not done any coding at all before then you probably should learn the basics of Java before reading it
Click to expand...
Click to collapse
thanks man! this really helps
Jonny said:
Fragments, ListViews, JSON parsing (for communication with the web server to download news etc), Android SQLite databases (I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example), Google Cloud Messaging notifications, notifications, encryption.
There are lots more but these are some of the main ones. In addition I would not advise trying to copy the "look" or aesthetics of the Harvard application as it frankly looks disgusting, whoever designed that needs a course in UI design
Click to expand...
Click to collapse
Thank you very much for the reply, I'm really thankful for the information that you share. Can you please clear this one for me?
I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example
Click to expand...
Click to collapse
clonedaccnt said:
Thank you very much for the reply, I'm really thankful for the information that you share. Can you please clear this one for me?
Click to expand...
Click to collapse
When you get data from a server to an Android app you use php for the server code - for example you can use php/mysql to run a search for calendar events in the database and return those events. Then you need to use php's JSON encode function to send the data in a JSON array.
The output should look something like this - this is the output of the calendar database for my school:
http://wgsb.cobainschofield.com/android_db/get_calendar.php (note this is not the live schools site, its the test server the guy who maintains the live site allows me to mess with err use).
You would then use a JSON parser class and an AsyncTask from within the app to "download" the content of the JSON array and then display it in a listview or textview etc.
Now obviously to get this information requires an internet connection yes? So every time someone wanted to check for an event on the calendar or read a news article for example they would need a working internet connection to receive the output of the get_calendar script, this is inefficient and bad design as it does not allow for offline viewing of the data.
Therefore what you can do is use androids SQLite implementation to create a local sql database then the first time you need to get the data from the webserver, you connect to the internet and get the output of the php script, the using the JSON parser class you store the information in the sqlite database then get the information from the database to display to the user.
By this way users can view news articles or calendar events offline and you only need to connect to the internet to refresh the information
I've uploaded screenshots in the attachments of how I've done it for my school's app.
That made it clear! Thank you very much.

playing audio files in an app

Hi there
I am desperate for advice and support on how to develop an android app that plays music audio files.
The app itself would have a home screen, about screen and a tracks screen.
The user when they navigate to tracks screen would have a list view of music audio files they can listen to on their android device.
The music audio file itself can either be stored in a SQL server database or ftp site , I don't know what would be best in terms of delivering optimal performance for end user?
The app would be like a service that would just play in the back ground allowing users to use their phone whilst listening to the music track(s).
My problems are:
- how can I actually develop this?
- there are no tutorials on the net, all music playing apps on YouTube, stack overflow and other websites do not show how to read music from SQL or ftp server.
I would be eternally grateful to anyone who could kindly advise me:
- best way to store each music audio file? Ftp or SQL
- in any case SQL would have to be used I believe to store the weblinks if I were to use FTP
- each music file of which there are around 150-180 is around 100mb in size and is of mp3 quality
Please , please , please can you help me develop this? Or guide me so I may be able to do it.
Please advise me on best way to set this up and get me started...
Thank you in advance
xirokx said:
Hi there
I am desperate for advice and support on how to develop an android app that plays music audio files.
The app itself would have a home screen, about screen and a tracks screen.
The user when they navigate to tracks screen would have a list view of music audio files they can listen to on their android device.
The music audio file itself can either be stored in a SQL server database or ftp site , I don't know what would be best in terms of delivering optimal performance for end user?
The app would be like a service that would just play in the back ground allowing users to use their phone whilst listening to the music track(s).
My problems are:
- how can I actually develop this?
- there are no tutorials on the net, all music playing apps on YouTube, stack overflow and other websites do not show how to read music from SQL or ftp server.
I would be eternally grateful to anyone who could kindly advise me:
- best way to store each music audio file? Ftp or SQL
- in any case SQL would have to be used I believe to store the weblinks if I were to use FTP
- each music file of which there are around 150-180 is around 100mb in size and is of mp3 quality
Please , please , please can you help me develop this? Or guide me so I may be able to do it.
Please advise me on best way to set this up and get me started...
Thank you in advance
Click to expand...
Click to collapse
sounds like you need to do lots more research and maybe a few tutorials for a better understanding. I would suspect 99% of developers would host file though http/s (not ftp) and yes all song info and metadata in SQL and delivered though php.
Binary Storage in SQL is not out of the question using BLOBS but not well suited in your case.
hope that helps, sounds simple enough
sounds like you need to do lots more research and maybe a few tutorials for a better understanding.
Click to expand...
Click to collapse
thanks for your reply
i have tried looking for tutorials for hours on end and its a very niche area, i could not find any.....do you know of any? have you tried looking for tutorials?
I would suspect 99% of developers would host file though http/s (not ftp) and yes all song info and metadata in SQL and delivered though php.
Click to expand...
Click to collapse
how do you host mp3 files using HTTPs ?
sounds simple enough
Click to expand...
Click to collapse
if its that simple, perhaps you would not mind guiding me to acheive it?
the page in the app which contains the mp3 files would have a listview or gridview with the names of the mp3s so when user clicks on them the mp3 plays in the background...
perhaps you can create an example if possible? i would be so grateful.
thank you
xirokx said:
i have tried looking for tutorials for hours on end and its a very niche area, i could not find any.....do you know of any? have you tried looking for tutorials?
Click to expand...
Click to collapse
You will never find a tutorial to do an exact app for what you want But you will find 1000's of how to store and use data from a database, 1000's for how to use mySQL and php in android, 1000's for listviews and gridviews powered by adapters and data and again 1000's or hundreds on how to stream audio from web servers using android
xirokx said:
how do you host mp3 files using HTTPs ?
Click to expand...
Click to collapse
upload them ? not sure what your question is here, you place the file on the server and use the URL ?
xirokx said:
if its that simple, perhaps you would not mind guiding me to achieve it?
the page in the app which contains the mp3 files would have a listview or gridview with the names of the mp3s so when user clicks on them the mp3 plays in the background...
perhaps you can create an example if possible? i would be so grateful.
thank you
Click to expand...
Click to collapse
It contains such a generic set of tasks you really dont need me to write it for you.... I'm always happy to answer direct specific questions, but you will seldom get an answer for "how do I do x app"... but like I said, what you want is very common, so there is tonnes of resource online
thanks for your reply
You will never find a tutorial to do an exact app for what you want But you will find 1000's of how to store and use data from a database, 1000's for how to use mySQL and php in android, 1000's for listviews and gridviews powered by adapters and data and again 1000's or hundreds on how to stream audio from web servers using android
Click to expand...
Click to collapse
If only the world was perfect and I could find an "exact" tutorial.....If I thought it was that easy I would never have started my thread.
really? 1000s or 100s.....yet you cannot point me to one?
It contains such a generic set of tasks you really dont need me to write it for you.... I'm always happy to answer direct specific questions, but you will seldom get an answer for "how do I do x app"... but like I said, what you want is very common, so there is tonnes of resource online
Click to expand...
Click to collapse
if it is that generic and simple, I do not understand why you cannot guide me more, at least to the 1000's or 100's of tutorials you claim that exist and especially as I have mentioned I cannot find them.
Try and see it from my point of view, I am new to this, trying, well actually REALLY REALLY want to learn, have spent hours researching for adhoc tutorials that will enable me to grasp the "generic" concept and have not found much / anything to help me.
Then you come along and make such a bold claim basically saying its "simple and easy, generic and quite straightforward" yet you cannot backup your claim by providing any of these "easy to find, 1000's or 100s tutorials" and are not willing to help any more then this.
Personally if I thought something was that easy, how much of my valuable time is it really going to take me, to provide someone who wants to learn with a few lines of code to get them started, especially after making such BOLD claims....
If I was not willing to, I would not even bother replying, it would have been far more beneficial if you responded with some example code rather then claiming how simple it was to do, I see no evidence that is it so easy only your claims...
Thanks for your time
Seriously though, this is me using google
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/training/basics/data-storage/databases.html
http://www.vogella.com/tutorials/AndroidSQLite/article.html
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
http://www.mybringback.com/tutorial...-using-remote-databases-php-and-mysql-part-1/
http://forum.xda-developers.com/showthread.php?t=2325799
http://developer.android.com/guide/topics/media/mediaplayer.html
http://stackoverflow.com/questions/18174068/how-to-play-the-online-streaming-radio-in-android
http://stackoverflow.com/questions/1965784/streaming-audio-from-a-url-in-android-using-mediaplayer
if you use google you will find 1000's more results, they were just the top ones really, not sure why you cant find any...seriously pages and pages of relevant results, what were you actually searching for ? as in search terms ... maybe thats the prob ?
Also yes it is generic and yes almost every app uses those components and has had to complete those tasks. Trust me on this, remote database + online resources are in 90% of apps But it's the tasks that have 1000s of tutorials and reference, not the app.... like i say "android database tutorial", "android mysql online database","android media stream url"
hope that helps
thanks alot....I will check them out and get back to you
so grateful for your help
maybe you can solve this, perhaps its "challenging" enough for ya
this is my android java code that a) connects to my db b) uses the Name field from my db to populate a listview in my app c) when any single listview item is selected, it uses the name in the listview matches it to the dbName and plays the dbFile which contain a URL to where the mp3 is stored:
Code:
private void connect() {
List<String> r = new ArrayList<String>();
ArrayAdapter<String>adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,r);
final ListView list=(ListView)findViewById(R.id.listView1);
try {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("myServer/android/files.php");
HttpResponse response = client.execute(request);
HttpEntity entity=response.getEntity();
data=EntityUtils.toString(entity);
Log.e("STRING", data);
try {
JSONObject jsonResponse = new JSONObject(data);
JSONArray jsonMainNode = jsonResponse.optJSONArray("mp3s");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
ID = jsonChildNode.getInt("ID");
name = jsonChildNode.getString("Name");
FileName = Uri.parse(jsonChildNode.getString("FileName"));
Log.e("STRING", name);
//r.add(ID);
r.add(name);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
MediaPlayer mp = new MediaPlayer();
try{
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(getApplicationContext(), FileName);
mp.prepare();
mp.start();
}
catch(IOException e)
{
System.out.println(e);
}
}
});
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClientProtocolException e) {
Log.d("HTTPCLIENT", e.getLocalizedMessage());
} catch (IOException e) {
Log.d("HTTPCLIENT", e.getLocalizedMessage());
}
}
Problem is:
- It doesnt open mediaplayer or streaming player on the emulator
- If track 1 is playing and I click on track 3 it plays both tracks simulateously
- as there is no media/stream player view you cannot pause/stop/play the track that is being played
pls help me fix these issues, if you can
thanks
p.s. I did use your links to get me this far, now I am genuinely stuck and would really appreciate a hand
thanks appreciate it
xirokx said:
Problem is:
- It doesnt open mediaplayer or streaming player on the emulator
Click to expand...
Click to collapse
Dont work with the emulator at all, I only use real devices, but if you mean the media player app, then thats due to you not using it. You're using the media player class.
xirokx said:
- If track 1 is playing and I click on track 3 it plays both tracks simulateously
Click to expand...
Click to collapse
Thats cause you create another instance that every click (or new instance rather). I would assume that you just should have 1 and stop/reuse it.
xirokx said:
- as there is no media/stream player view you cannot pause/stop/play the track that is being played
Click to expand...
Click to collapse
Well you would create buttons to do that yourself.
I am now debugging my app on my device
I have changed the code a little so only 1 file plays at any one time and it works....
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
//playAudio(FileName);
Uri uri = FileName;
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Click to expand...
Click to collapse
However when I click on the list item, a menu opens up asking which browser I want to play the file in....when instead it should open a list of mediaplayers for me to play the file in.
How can I change it?
Thanks for your help.
xirokx said:
I am now debugging my app on my device
I have changed the code a little so only 1 file plays at any one time and it works....
However when I click on the list item, a menu opens up asking which browser I want to play the file in....when instead it should open a list of mediaplayers for me to play the file in.
How can I change it?
Thanks for your help.
Click to expand...
Click to collapse
well thats the way it will work if down to the user not choosing a default and also the way you set it up.... I do reccomend you read the android docs like http://developer.android.com/guide/components/intents-filters.html
it will help when asking question and most of the time you wont have to ask cause the answers are there.

[Q] Extract JSON data and display in ListView with Searchbox

Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.
ajitmenezes said:
Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.
Click to expand...
Click to collapse
You should implement the search on the listview adapter, not on the activity itself.
Take a look at the following article:
http://www.mokasocial.com/2010/07/arrayadapte-filtering-and-you/

[Q] Android studio xml pull parser

I have been trying to find out how to parse TechCrucchs rss feed and use the information in my android app.
The problem is that I the information I find is either outdated, incorrect or just incomprehensible. So how do I get and use the information from this feed?
Pauly69 said:
I have been trying to find out how to parse TechCrucchs rss feed and use the information in my android app.
The problem is that I the information I find is either outdated, incorrect or just incomprehensible. So how do I get and use the information from this feed?
Click to expand...
Click to collapse
I played around with an RSS reader app, and I used this tutorial http://jmsliu.com/1390/rss-reader-app-android-tutorial-1-listview-and-arrayadapter.html which worked for me.
Check HTTP request code (urls and parameters). Maybe, you request wrong data (e.g. wrong date, period or some other param).

Categories

Resources