Langsung ke konten utama

Postingan

Menampilkan postingan dengan label Retrofit

Upload File to Server using Retrofit in Android

Hello friends, In this post, I will show you how to upload Image/Video/Any Files to the Server in Android using Retrofit 2. In Retrofit 2 Image or any type of files will be uploaded as Multipart. The File is received using php. This Code is Updated with Multiple File Upload. Upload Single File Web Part: Create a PHP file named as upload_image.php and paste the following lines. <?php $target_dir = "uploads/"; $target_file_name = $target_dir .basename($_FILES["file"]["name"]); $response = array(); // Check if image file is a actual image or fake image if (isset($_FILES["file"])) { if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file_name)) { $success = true; $message = "Successfully Uploaded"; } else { $success = false; $message = "Error while uploading"; } } else { $success = false; $message = "Required Field Missing"; } $response[...

How to Perform Rest API using Retrofit in Android (Part-2)

In this post, I will show you How to use Retrofit in Android. Retrofit is a new born baby of web services such as AsyncTask, JSONParsing and Volley.In Previous Part , I showed the PHP Scripts to perform basic CRUD operations. In this part, Contains the informations about how to perform Retrofit Operations in Android. Project Structure: Create New Project in Android Studio with blank activity as in the following. We need Retrofit Library for working with that. For Android Studio you just need to paste below line of code under dependency of build.gradle file. compile 'com.squareup.retrofit:retrofit:1.9.0' For eclipse users download jar file from below link and add to you project. Download jar AndroidManifest.xml Don't forget to add the following permission in your manifest file <uses-permission android:name="android.permission.INTERNET"/> AppConfig.class Create AppConfig.class and replace it with the following code.It is used as helper class for web services...

How to Perform Rest API using Retrofit in Android (Part-1)

In this post, I will show you How to use Retrofit in Android. Retrofit is a new born baby of web services such as AsyncTask, JSONParsing and Volley. This post is Split into Two Parts. First Part Contains Architecture of Retrofit and How to create MySQL DB and PHP Scripts for Basic Operations. Second Part Contains how to perform Retrofit Operations in Android. Architecture of Retrofit Web Service We need 3 Things for Complete Retrofit Architecture. RestAdapter An Interface with all networking methods and parameters. Getter Setter Class to save data coming from server. Project Structure: Create MySQL DataBase and PHP Scripts. Following image shows my database structure. PHP Scripts: I created db_config.php which contains the script to connect DB. <?php /** * Database config variables */ define("DB_HOST", "localhost"); define("DB_USER", "root"); define("DB_PASSWORD", ""); define("DB_DATABASE", "retrofit_exampl...