fbpx <h1>bloggerpins -Make your Blog| Tips and Tricks| Marketing| SEO</h1>

Now, let’s Convert Your Blogger Blog Into An App.

Now, let’s Convert Your Blogger Blog Into An App. 1

It is not possible to get your laptop wherever you go. If you have an enormous idea, then you may not be able to share with your readers. At the very moment, you might be thinking of a pocket technology, which can take to anywhere and share your thought immediately. Don’t worry!! You can do it. It’s very easy to share your blogs regularly with your clients from anyplace, and anytime, and keep them drew in more than ever.

WP REST API helps the developers to build an application which can be easily integrated with the WordPress platform. Making use of this API, we can easily recover our WordPress site’s information like posts, media, clients, and so forth in JSON format. Here, I will show you to make an exceptionally essential Android application for WordPress blog or site using the WP REST API.

 

How to function WP REST API?

To utilize WP REST API we require following two plugins. So, initially install these plugins in your WordPress blog.

Install REST API Plugins

WordPress REST API (Version 2)

The official WP REST API plugin is used to get information from blogs.

REST API – Filter Fields

The JSON information that we fetch contains fewer fields that we don’t require. So utilizing these plugins, we can filter the information to reduce its size.

Fetching All the posts on your site.

  • You can fetch data about all the post on your blog,

by using the given URL.

http://your-blog-url/wp-json/wp/v2/posts

For example,

http://www.freerooter.com//wp-json/wp/v2/posts?

 

For Fetching Specified Number of Post

For fetching the particular number of your posts, you can use a filter named  post-per-page. The below URL will fetch only 3 posts.

http://your-blog-url/wp-json/wp/v2/posts?filter[posts_per_page]=3

For fetching a specified Post, you

You can fetch any particular post by its id.

http://your-blog-url/wp-json/wp/v2/posts/57

Given the above “57” is the id of the post.

 

Filtering Fields

As you have seen in the above JSON information, that there are a few fields that we don’t require. So with the help of REST API – Filter Fields plugin can filter few fields. For instance, you need to get just the post’s id and title. This is possible by making use of the following URL.

http://your-blog-url/wp-json/wp/v2/posts?fields=id,title

 

Creating WordPress to Android App Project

  • First, Open  Android Studio and Create a new Project.
  • We need the subsequent dependency to add to our app-level “build.gradle file”.

 

  • compile ‘com.google.code.gson:gson:2.2.+’
  • compile ‘com.android.volley:volley:1.0.0’

Add internet access permission by adding the given line in AndroidManifest.xml file.

<uses-permission android:name=”android.permission.INTERNET” />

  • For this, first we have to  create a RecycleView in our activity_main.xml. In this RecycleView we will be able to see the latest posts fetched from the REST API.

 

recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());//

recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());

RAC = new RecylerAdapterClass(getApplicationContext(),parameter);

recyclerView.setAdapter(RAC);

//  for  loading image

Picasso.with(cntx).load
      (String.valueOf(image_url.get(position))).placeholder(R.drawable.splashscreenicon)

.error(R.drawable.splashscreenicon).into(holder.img);

 

  • Now, it’s time to create a new file named post.xml inside directory layout and write the following code.  This file will be used to show the selected post.

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”

    android:layout_width=”match_parent”

    android:layout_height=”match_parent”

    android:orientation=”vertical”>

 

    <TextView

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:id=”@+id/title”

        android:layout_marginBottom=”2dp”

        android:textSize=”15dp”

        android:padding=”8dp”

        android:textColor=”#ffffff”/>

 

    <WebView

        android:layout_width=”match_parent”

        android:layout_height=”wrap_content”

        android:id=”@+id/details ” />

 

</LinearLayout>

 

  • Now get into the  MainActivity.java and write the subsequent code.
  • Develop a New Activity for displaying the selected post. Now we have created Post.java

 

String htmlText = ” %s “;
WebSettings settings = content.getSettings();
settings.setDefaultTextEncodingName(“utf-8”);
String data=“<html>”  + “<body style=’text-align: justify;’>” + PostData.getInstance().getContent().get(position) + “</body></html>”;
Log.d(“——“,data);
content.loadDataWithBaseURL(null, “<style>img{display: inline;height: auto;max-width: 100%;}</style>” + data, “text/html”, “UTF-8”, null);

 

Now it’s time to run your application. To just ensure that you have changed the URLs with your own blog and installed the REST API was Plugin properly. Given below are the screenshot of the blog- app pages.

 

  • If you click on a particular post, you can view the complete post. So we can ensure that our app is working good. Never stop working on your app. You still have to improve the user interface design. So try to make your app perfect!!!

 

You May Also Like:

What is meant by App Store Optimization(ASO)

Leave a Reply