1- Send Multiple Image to Server :
2-Send video to Server :
3-Send Single Image to server :
4-Send Text to server :
Here we are sending those faild in single time on server :
1. Main Activity.java code :
package com.like.maxtratechnologies;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.Manifest;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import com.google.android.material.textfield.TextInputEditText;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
private Button btn,Upload_Data;
private VideoView videoView;
private static final String VIDEO_DIRECTORY = "/demonuts";
private int GALLERY = 1, CAMERA = 2;
private TextInputEditText Name,Description;
RecyclerView recyclerView;
TextView textView;
Button button;
ArrayList<Uri> list;
RecyclerAdaptor adaptor;
Button BSelectImage;
Uri selectedImageUri;
Uri contentVideoURI;
public static final String MIME_TYPE_TEXT = "text/*";
public static final String MIME_TYPE_IMAGE = "image/*";
ImageView IVPreviewImage;
int SELECT_PICTURE = 200;
String colum[]={
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
Upload_Data = (Button) findViewById(R.id.Upload_Data);
videoView = (VideoView) findViewById(R.id.vv);
BSelectImage = findViewById(R.id.BSelectImage);
IVPreviewImage = findViewById(R.id.IVPreviewImage);
progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
Name = findViewById(R.id.firstname_editText);
Description = findViewById(R.id.discruption);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((ActivityCompat.checkSelfPermission(MainActivity.this
,colum[0])!= PackageManager.PERMISSION_GRANTED)&&
(ActivityCompat.checkSelfPermission(MainActivity.this
,colum[1])!= PackageManager.PERMISSION_GRANTED)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(colum,123);
}
}
showPictureDialog();
}
});
BSelectImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((ActivityCompat.checkSelfPermission(MainActivity.this
,colum[0])!= PackageManager.PERMISSION_GRANTED)&&
(ActivityCompat.checkSelfPermission(MainActivity.this
,colum[1])!= PackageManager.PERMISSION_GRANTED)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(colum,123);
}
}
imageChooser();
}
});
list=new ArrayList<>();
recyclerView=findViewById(R.id.recycler);
textView=findViewById(R.id.textView);
button=findViewById(R.id.button);
adaptor=new RecyclerAdaptor(list);
recyclerView.setLayoutManager(new GridLayoutManager(MainActivity.this,3));
recyclerView.setAdapter(adaptor);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openGalley();
}
});
Upload_Data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uploaddata();
}
});
}
private void Uploaddata() {
progress.show();
RequestBody requestName =
RequestBody.create(
MediaType.parse("text/plain"), Name.getText().toString().trim());
RequestBody requestDescription =
RequestBody.create(
MediaType.parse("text/plain"), Description.getText().toString().trim());
RequestBody requestPostType =
RequestBody.create(
MediaType.parse("text/plain"), "1");
RequestBody requestUserId =
RequestBody.create(
MediaType.parse("text/plain"), "100");
MultipartBody.Part imagenPerfil = null;
if(selectedImageUri!=null){
imagenPerfil = prepareFilePart("video_thumbnail", selectedImageUri);
}
MultipartBody.Part videoPerfil = null;
if(contentVideoURI!=null){
File file = new File(getPath(contentVideoURI));
Log.d("file_path",file.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
videoPerfil = MultipartBody.Part.createFormData("videos", file.getName(), requestBody);
}
List<MultipartBody.Part> parts = new ArrayList<>();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
parts.add(prepareFilePart("images[]", list.get(i)));
}
}
Call<ApiResponse> call = RetrofitClient.getInstance()
.getApi().addPost(parts,videoPerfil,imagenPerfil,requestName,
requestPostType,requestDescription,requestUserId);
call.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
Log.d("response","Successful");
progress.hide();
if (response.isSuccessful()) {
Toast.makeText(MainActivity.this, "Successful", Toast.LENGTH_SHORT).show();
ApiResponse apiResponse = response.body();
} else if (response.code() == 401) {
Toast.makeText(MainActivity.this, "Your Session has been Expiered,Please Login Again..",
Toast.LENGTH_SHORT).show();
} else if (response.code() == 500) {
Toast.makeText(MainActivity.this, "Server Error", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Failed to Retrieve Items..", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ApiResponse> call, Throwable t) {
progress.hide();
Toast.makeText(MainActivity.this, t.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
}
private void showPictureDialog(){
AlertDialog.Builder pictureDialog = new AlertDialog.Builder(this);
pictureDialog.setTitle("Select Action");
String[] pictureDialogItems = {
"Select video from gallery"};
pictureDialog.setItems(pictureDialogItems,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
chooseVideoFromGallary();
break;
case 1:
}
}
});
pictureDialog.show();
}
public void chooseVideoFromGallary() {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, GALLERY);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("result",""+resultCode);
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == this.RESULT_CANCELED) {
Log.d("what","cancle");
return;
} else if(requestCode==123 && resultCode==RESULT_OK){
if(data.getClipData()!=null){
int x=data.getClipData().getItemCount();
for(int i=0;i<x;i++){
list.add(data.getClipData().getItemAt(i).getUri());
}
adaptor.notifyDataSetChanged();
textView.setText("Image("+list.size()+")");
}else if(data.getData()!=null){
String imgurl=data.getData().getPath();
list.add(Uri.parse(imgurl));
}
} else if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedImageUri = data.getData();
if (null != selectedImageUri) {
IVPreviewImage.setImageURI(selectedImageUri);
}
}
}
if (requestCode == GALLERY) {
Log.d("what","gale");
if (data != null) {
contentVideoURI = data.getData();
String selectedVideoPath = getPath(contentVideoURI);
Log.d("path",selectedVideoPath);
saveVideoToInternalStorage(selectedVideoPath);
videoView.setVideoURI(contentVideoURI);
videoView.requestFocus();
videoView.start();
}
} else if (requestCode == CAMERA) {
Uri contentURI = data.getData();
String recordedVideoPath = getPath(contentURI);
Log.d("frrr",recordedVideoPath);
saveVideoToInternalStorage(recordedVideoPath);
videoView.setVideoURI(contentURI);
videoView.requestFocus();
videoView.start();
}
}
private void saveVideoToInternalStorage (String filePath) {
File newfile;
try {
File currentFile = new File(filePath);
File wallpaperDirectory = new File(Environment.getExternalStorageDirectory() + VIDEO_DIRECTORY);
newfile = new File(wallpaperDirectory, Calendar.getInstance().getTimeInMillis() + ".mp4");
if (!wallpaperDirectory.exists()) {
wallpaperDirectory.mkdirs();
}
if(currentFile.exists()){
InputStream in = new FileInputStream(currentFile);
OutputStream out = new FileOutputStream(newfile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v("vii", "Video file saved successfully.");
}else{
Log.v("vii", "Video saving failed. Source file missing.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
private void openGalley() {
Intent intent=new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Selcet Picture"),123);
}
void imageChooser() {
if((ActivityCompat.checkSelfPermission(
this,colum[0])!= PackageManager.PERMISSION_GRANTED)&&
(ActivityCompat.checkSelfPermission(
this,colum[1])!= PackageManager.PERMISSION_GRANTED)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(colum,123);
}
}
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(i, "Select Picture"), SELECT_PICTURE);
}
@NonNull
private RequestBody createPartFromString(String descriptionString) {
return RequestBody.create(MediaType.parse(MIME_TYPE_TEXT), descriptionString);
}
@NonNull
private MultipartBody.Part prepareFilePart(String partName, Uri fileUri) {
File file = FileUtils.getFile(MainActivity.this, fileUri);
Log.d("file_path",file.getAbsolutePath());
RequestBody requestFile = RequestBody.create (MediaType.parse(MIME_TYPE_IMAGE), file);
Log.d("file","file"+requestFile);
return MultipartBody.Part.createFormData(partName, file.getName(), requestFile);
}
}
2-Main Activity.xml code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeColor="@color/colorPrimary"
app:boxStrokeWidthFocused="2dp"
app:endIconMode="clear_text"
app:endIconTint="@color/colorPrimary"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:hintTextColor="@color/black"
app:startIconTint="@color/colorBTN"
android:layout_gravity="center"
app:startIconDrawable="@drawable/ic_baseline_person_24"
android:hint="Name"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstname_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/purple_700"
android:drawableTint="@color/btnbackground"
android:inputType="text">
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeColor="@color/colorPrimary"
app:boxStrokeWidthFocused="2dp"
app:endIconMode="clear_text"
app:endIconTint="@color/colorPrimary"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:hintTextColor="@color/black"
app:startIconTint="@color/colorBTN"
android:layout_gravity="center"
app:startIconDrawable="@drawable/ic_baseline_summarize_24"
android:hint="description"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/discruption"
android:backgroundTint="@color/purple_700"
android:drawableTint="@color/btnbackground"
android:inputType="textMultiLine">
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Pick Videos"
android:textAllCaps="false"
android:layout_gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.445"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeColor="@color/purple_700" />
<VideoView
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_margin="8dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
android:id="@+id/vv"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/BSelectImage"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Pick Image for video thumbnail"
android:textAllCaps="false"
android:layout_gravity="center"
app:strokeColor="@color/purple_700" />
<ImageView
android:id="@+id/IVPreviewImage"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="100dp"
android:layout_margin="8dp"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick Multiple Images"
android:textAllCaps="false"
android:layout_gravity="center"
app:strokeColor="@color/purple_700" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Image Count:"
android:layout_marginLeft="8dp"
android:textColor="@color/purple_700"
android:textSize="18sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_margin="8dp"
android:layout_height="wrap_content"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/Upload_Data"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload All Data"
android:textAllCaps="false"
android:layout_marginBottom="5dp"
android:layout_gravity="center"
app:strokeColor="@color/purple_700" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Make recyclerView for showing uploaded muliple image :
3-Create Adapter class for recyclerView :
package com.like.maxtratechnologies;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class RecyclerAdaptor extends RecyclerView.Adapter<RecyclerAdaptor.ViewHolder> {
private ArrayList list;
public RecyclerAdaptor(ArrayList list) {
this.list = list;
}
@NonNull
@Override
public RecyclerAdaptor.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view =inflater.inflate(R.layout.custom_item_layout,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerAdaptor.ViewHolder holder, int position) {
holder.imageView.setImageURI((Uri) list.get(position));
}
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
public ViewHolder(@NonNull View itemView) {
super(itemView);
imageView=itemView.findViewById(R.id.imageView);
}
}
}
4- Layout for Showing multiple Image views :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:cardCornerRadius="8dp"
android:layout_margin="8dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:src="@drawable/background1"
android:scaleType="fitXY"
app:layout_constraintDimensionRatio="1"
tools:ignore="Suspicious0dp" />
</androidx.cardview.widget.CardView>
5-create api interface for retrofit http reqest :
package com.like.maxtratechnologies;
import java.util.List;
import java.util.Map;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
public interface Api {
@Multipart
@POST("create_post")
Call<ApiResponse> addPost(@Part List<MultipartBody.Part> images,
@Part MultipartBody.Part videos,
@Part MultipartBody.Part video_thumbnail,
@Part("name") RequestBody name,
@Part("post_type") RequestBody post_type,
@Part("discription") RequestBody discription,
@Part("user_id") RequestBody user_id);
}6-create retrofit client class :
package com.like.maxtratechnologies;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static final String BASE_URL ="http://182.76.237.238/~apitest/sme_link/api/";
private static RetrofitClient mInstance;
private Retrofit retrofit;
private RetrofitClient(){
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
.addInterceptor(logging)
.callTimeout(20, TimeUnit.MINUTES)
.connectTimeout(10, TimeUnit.MINUTES)
.readTimeout(50, TimeUnit.MINUTES)
.writeTimeout(50, TimeUnit.MINUTES);
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
}
public static synchronized RetrofitClient getInstance(){
if(mInstance == null){
mInstance = new RetrofitClient();
}
return mInstance;
}
public Api getApi(){
return retrofit.create(Api.class);
}
}6- create FileUtils class :
fileUtils class useful for working with files. Summary. Nested classes. abstract class .nested method .we write code here for finding path of file ..package com.like.maxtratechnologies;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import java.io.File;
public class FileUtils {
private FileUtils() {} //private constructor to enforce Singleton pattern
/** TAG for log messages. */
private static final String TAG = "FileUtils";
private static final boolean DEBUG = false; // Set to true to enable logging
public static final String MIME_TYPE_AUDIO = "audio/*";
public static final String MIME_TYPE_TEXT = "text/*";
public static final String MIME_TYPE_IMAGE = "image/*";
public static final String MIME_TYPE_VIDEO = "video/*";
public static final String MIME_TYPE_APP = "application/*";
public static final String HIDDEN_PREFIX = ".";
public static String getExtension(String uri) {
if (uri == null) {
return null;
}
int dot = uri.lastIndexOf(".");
if (dot >= 0) {
return uri.substring(dot);
} else {
// No extension.
return "";
}
}
public static File getFile(Context context, Uri uri) {
String path = getPath(context, uri);
assert path != null;
return new File(path);
}
public static String getPath(Context context, Uri uri) {
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory().getPath() + "/" + split[1];
}
// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.
parse("content://downloads/public_downloads"), Long.parseLong(id));
return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {split[1]};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = { column };
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos.
*/
private static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
}7- create class for APi Responce :
package com.like.maxtratechnologies;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ApiResponse {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("message")
@Expose
private String message;
@SerializedName("data")
@Expose
private Data data;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public class Data{
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("user_id")
@Expose
private Integer userId;
@SerializedName("group_id")
@Expose
private Object groupId;
@SerializedName("name")
@Expose
private String name;
@SerializedName("post_type")
@Expose
private String postType;
@SerializedName("discription")
@Expose
private String discription;
@SerializedName("images")
@Expose
private Object images;
@SerializedName("videos")
@Expose
private Object videos;
@SerializedName("video_thumbnail")
@Expose
private Object videoThumbnail;
@SerializedName("created_at")
@Expose
private String createdAt;
@SerializedName("updated_at")
@Expose
private String updatedAt;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Object getGroupId() {
return groupId;
}
public void setGroupId(Object groupId) {
this.groupId = groupId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPostType() {
return postType;
}
public void setPostType(String postType) {
this.postType = postType;
}
public String getDiscription() {
return discription;
}
public void setDiscription(String discription) {
this.discription = discription;
}
public Object getImages() {
return images;
}
public void setImages(Object images) {
this.images = images;
}
public Object getVideos() {
return videos;
}
public void setVideos(Object videos) {
this.videos = videos;
}
public Object getVideoThumbnail() {
return videoThumbnail;
}
public void setVideoThumbnail(Object videoThumbnail) {
this.videoThumbnail = videoThumbnail;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
}
✅ Tags
send-multiple-image