I’m trying to develop an Android app for browsing a WordPress-powered blog I own. I’m trying to figure out how to retrieve posts and other information from the blog to display in the app. I’ve looked all over but I feel completely lost. Is this something that can be done entirely in Java/XML? If so, how?
Thank you!
Yes, it can be done.
One way is to use the xml-rpc api. WordPress blogs have an xml-rpc api(which you need to enable on the WordPress blog under “Settings – Writing”). You will also need to create a user on the blog, which you give at least read access, and for which you include the credentials in your app.
From then on, you can do xml-rpc calls to your WordPress blog(s).
If using this xml-rpc api is an option, take a look at this Java lib: http://code.google.com/p/wordpress-java/
You can get the blogposts using this lib like this:
Also, the official WordPress Android app is open source. Instructions to get it are at: http://android.wordpress.org/development/
You could use this source code as a starting point and adapt it to your needs.
Note that you can only use the xml-rpc api when you have a user with read access. If you do not have the credentials of a user with read access, you can’t get the posts using the xml-rpc api.
Fetching the rss feed and parsing the rss feed with some java lib would probably be your best bet then(check http://www.vogella.com/articles/RSSFeed/article.html on how to read an rss feed using Java).
As Integrating Stuff said, the ‘net.bican:jwordpress:0.6.4’ is what you need.
Still, the example he gave is now deprecated. There is no more getRecentPosts(int) but getPosts(FilterPost).
So now the correct code is :
to know more check the example :
https://github.com/canbican/wordpress-java/blob/bb4b60a008ee6d280aedd9174df4a657bff683ac/src/net/bican/wordpress/example/Main.java
Also, if you’re using Gradle, check this dependencies problem you may face :
https://github.com/canbican/wordpress-java/issues/54
There is an alternative way also , and its working good,
you can install json plugin in your word press and you can retrieve all the post by requesting the url … and parsing the response json in your android views will be working .