Hello every one iam working on a social app which on of its features is uploading images
i Use Firebase in this project
but for a starter project i use Free plan for which gives me 5GB storage free
So i want to know how to Reduce the image Quality or Resolution before it uploaded to the Storage to save Storage place
here is my code
UploadpostActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_REQUEST && resultCode ==RESULT_OK ){
mImageURI = data.getData();
imgSelector.setImageURI(mImageURI);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
btnUpload=(Button)findViewById(R.id.upload);
imgSelector =(ImageView) findViewById(R.id.selectImage);
postDescription = (EditText)findViewById(R.id.descpost);
postTitle = (EditText)findViewById(R.id.titlepost);
mProgress= new ProgressDialog(this);
btnUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postnow();
}
});
imgSelector.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gallerySelectIntent = new
Intent(Intent.ACTION_GET_CONTENT);
gallerySelectIntent.setType("image/*");
startActivityForResult(gallerySelectIntent,GALLERY_REQUEST);
}
});
}
private void postnow(){
mProgress.setMessage("Uploading..");
mProgress.show();
String title= postTitle.getText().toString().trim();
String desc = postDescription.getText().toString().trim();
StorageReference pathfile = FirebaseStorage.getInstance()
.getReference("UsersImages")
.child(mImageURI.getLastPathSegment());
pathfile.putFile(mImageURI)
.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
{
// Get a URL to the uploaded content
Uri downloadUrl = taskSnapshot.getDownloadUrl();
mProgress.dismiss();
Toast.makeText(UploadActivity.this,"Upload
Successfully",Toast.LENGTH_LONG).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
Toast.makeText(UploadActivity.this,"Something Went Wrong
, Error",Toast.LENGTH_LONG).show();
}
});
}
}
I Appreciate your time