Android simple networking library.
- Add maven repository.
maven {
url 'https://dl.bintray.com/parksm/maven/'
}
- Add to build.gradle
implementation 'com.smparkworld.parkwork:parkwork:1.2.0'
- String request
HashMap<String, String> strData = new HashMap<>();
strData.put("exampleKey", "exampleData");
ParkWork.create(this, "") // Enter the Request-URI.
.setOnResponseListener(new ParkWork.OnResponseListener() {
@Override
public void onResponse(String response) {
// Enter the code to process after receiving data from the server.
}
@Override
public void onError(String errorMessage) {
// Enter the code to process after receiving error message from the ParkWork library.
}
})
.setStringData(strData)
.start();
// PHP ///////////////////////////////////////
<?php
$data = $_POST[exampleKey];
// Enter the code to process after receiving data from the device.
$response = $data." from server.";
echo $response;
?>
- Image Uploading
HashMap<String, String> imgData = new HashMap<>();
imgData.put("exampleKey", ""); // Enter the image URI of Content-path or Absolute-path.
ParkWork.create(this, "") // Enter the Request-URI.
.setOnResponseListener(new ParkWork.OnResponseListener() {
@Override
public void onResponse(String response) {
// Enter the code to process after receiving data from the server.
}
@Override
public void onError(String errorMessage) {
// Enter the code to process after receiving error message from the ParkWork library.
}
})
.setImageData(imgData)
.start();
// PHP ///////////////////////////////////////
<?php
$storage = ""; // Enter the directory path where the image will be saved
if($_FILES["exampleKey"]["error"] == 0) {
$fname = $_FILES["exampleKey"]["name"];
if(!move_uploaded_file($_FILES["exampleKey"]["tmp_name"], $storage.$fname))
exit("Error: Failed to upload image");
} else {
exit("Error: Not found image.");
}
echo("Success");
?>
- String request and Image uploading
HashMap<String, String> strData = new HashMap<>();
strData.put("exampleKey", "exampleData");
HashMap<String, String> imgData = new HashMap<>();
imgData.put("exampleKey", ""); // Enter the image URI of Content-path or Absolute-path.
ParkWork.create(this, "") // Please enter the URI.
.setOnResponseListener(new ParkWork.OnResponseListener() {
@Override
public void onResponse(String response) {
// Enter the code to process after receiving data from the server.
}
@Override
public void onError(String errorMessage) {
// Enter the code to process after receiving error message from the ParkWork library.
}
})
.setStringData(strData)
.setImageData(imgData)
.start();
// PHP ///////////////////////////////////////
<?php
$textData = $_GET[exampleKey];
$storage = ""; // Enter the directory path where the image will be saved
if($_FILES["exampleKey"]["error"] == 0) {
$fname = $_FILES["exampleKey"]["name"];
if(!move_uploaded_file($_FILES["exampleKey"]["tmp_name"], $storage.$fname))
exit("Error: Failed to upload image");
} else {
exit("Error: Not found image.");
}
echo("Success");
?>
- Get only response
ParkWork.create(this, "") // Enter the Request-URI.
.setListener(new ParkWork.OnResponseListener() {
@Override
public void onResponse(String response) {
// Enter the code to process after receiving data from the server.
}
@Override
public void onError(String errorMessage) {
// Enter the code to process after receiving error message from the ParkWork library.
}
})
.start();
- Receive progress info
HashMap<String, String> imgData = new HashMap<>();
imgData.put("exampleKey", ""); // Enter the image URI of Content-path or Absolute-path.
ParkWork.create(this, "") // Enter the Request-URI.
.setListener(new ParkWork.OnResponseListener() {
@Override
public void onResponse(String response) {
// Enter the code to process after receiving data from the server.
}
@Override
public void onError(String errorMessage) {
// Enter the code to process after receiving error message from the ParkWork library.
}
})
.setOnProgressUpdateListener(new ParkWork.OnProgressUpdateListener() {
@Override
public void onProgressUpdate(int progress) {
// The percentage of progress is returned as a parameter.
// For example, if you upload 4 images, 25 is returned.
}
})
.setImageData(imgData)
.start();
Copyright 2020 ParkSM Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.```