Showing posts with label android volley. Show all posts
Showing posts with label android volley. Show all posts

Saturday, 11 February 2017

Sending POST Request to Internet Using Android Volley

android volley library - android tech point
Android Volley Library Tutorial

Android Volley is an library for network operations in android development. It is a very light weight framework and most importantly, very fast for network operations. It has facility to get the raw string, image or JSON data over the network efficently. One of the benifit that I like the most if you can easily use volley in your activity as it automatically sends the request in separate thread. And also maintains a queue for the requests.
Note that volley is not for large data downloads as it holds all the data in memory. For large downloading use the DownloadManager.
Here is the demo video for this app.

Dependency for android volley

Minimum requirement for android volley Android 2.2 (API Level 8) or higher. Now come towards tutorial for android volley.

Steps for using Volley

  • Add the uses-permission in Android Manifest.xml file.
    <uses-permission android:name="android.permission.INTERNET"/>
  • Add the dependency in build.gradle (Module: app)
    compile 'com.android.volley:volley:1.0.0'
  • Write code for sending request in MainActivity.java
  • Write the server side code. I am using xampp and sending request to localhost. Follow tutorial here to configure xampp for accessing from other devices.
You can get the complete project at Github Repository. Or you can get the code below in this post.

MainAcitivty.java

activity_main.xml

androidvolley.php

In case of error

If you get some error, the first thing you should check is permissions in android androidManifest.xml and build.gradle. If you still get the error feel free to comment below or contact me at farooqahmadkhan003@gmail.com.

Monday, 30 January 2017

Android App for Login Sign Up Using Android Volley and php

In this tutorial we are going code back-end for the Android App we build in other tutorial. For this we will use Android Volley to send request on server. Fortunately, Android studio does most of this part too. We only need to send the request for the login authentication or sign up from our android app.

Which is so simple using android volley and with piece of code, but I made some other changes too in the automatically generated code for our app. Read the comments in the code to understand the code completely. The main changes are:
  • Removed the Async Class as the android volley automatically send the network requests in threads. Android Studio add the async class for the network operations as no network operation can be performed in the main thread.
  • Remove all the relevant code to the async class.
  • Paste the url of your server in string.xml and also change the file name accordingly in the java files. You can make your laptop a server using xampp. Follow the tutorial here for further instructions if you get troubled.
I think that is pretty much all. The rest of code is same. Now move on the tutorial part. The step by step break down for the android app is as follows:
  • Add the uses-permission in Android Manifest file.
    <uses-permission android:name="android.permission.INTERNET"/>
  • Add the dependency for Android Volley in build.gradle (Module: app).
    compile 'com.android.volley:volley:1.0.0'
  • Write the code to send request to server for login or sign up.
  • Write the server side code. For this tutorial I am just sending success from the server for both login.php and signup.php.
    <?php echo "success"; ?>
And that all. You are done with the Android App for Login and Sign Up. You can get the complete android app code with back-end at Github Repository. Or you can get the code below in this post for login and sign up classes.

LoginActivity.java


SignUp.java


In case of error

If you get some error, the first thing you should check is permissions in android androidManifest.xml and build.gradle. If you still get the error feel free to comment below or contact me at farooqahmadkhan003@gmail.com.