how to upload to firebase a file with firebase storage - android

i try to upload to firebase a picture and when i upload its show me that the size of the file is 0 bytes and dont show the content picture
everything seems fine, then whay its happen???
StorageReference storageRef = storage.getReferenceFromUrl("gs://<your-bucket-name>");
if (inputStream!=null) {
String pic = "BathroomImage" + +rand.nextInt(1000) + ".jpg";
mountainsRef = storageRef.child(pic);
uploadTask = mountainsRef.putStream(inputStream);
uploadTask.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d("this is the faiure:","hey im here");
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
taskSnapshot.getMetadata();
Uri downloadUri = taskSnapshot.getDownloadUrl();
bitmap.recycle();
bitmap=null;
System.gc();
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
here i upload the picture from the data to inputsream.
void TakePickphoto(){
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); // Create intent to Open Image applications like Gallery, Google Photos
startActivityForResult( galleryIntent, RESULT_LOAD_IMAGE);// Start the Intent
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode ==getActivity().RESULT_OK && null != data) {
selectedImage = data.getData(); // Get the URI Image from data
handler= new Handler();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
Runnable runnable = new Runnable() {
#Override
public void run() {
try {
inputStream = context.getContentResolver().openInputStream(data.getData());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize =4;
bitmap = BitmapFactory.decodeStream(inputStream, new Rect(40,40,40,40),options);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
handler.post(new Runnable() {
#Override
public void run() {
ImageView imageView;
imageView = (ImageView) view.findViewById(R.id.imageView2);
imageView.setImageBitmap(bitmap);
}
});
}
};
new Thread(runnable).start();
}
}
}
please help, everything look fine to me.

** This will not save the image in full resolution **
To save a picture in full resolution, research how to do that when you start the TakePictureIntent.
I had the same error and solved it by setting up my picture taking and uploading like this:
//takes the picture
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, 1);
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
//saves the pic locally
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] dataBAOS = baos.toByteArray();
/***************** UPLOADS THE PIC TO FIREBASE*****************/
// Points to the root reference
StorageReference storageRef = FirebaseStorage.getInstance().getReferenceFromUrl("your-root-storage-ref");
StorageReference imagesRef = storageRef.child("image");
UploadTask uploadTask = imagesRef.putBytes(dataBAOS);
uploadTask.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl();
}
});
}
}
This way it will compress and save your image in your Firebase Storage with this file struct:
root -> image

You can pass the InputStream directly from the Uri to the putStream method. You may want to resize the image yourself before uploading it, which would require a bit more work, but this way uses very little memory on the client side.
if (requestCode == IMAGE_PICKER_SELECT && resultCode == Activity.RESULT_OK) {
Uri imageUri = data.getData();
try {
ContentResolver contentResolver = getActivity().getContentResolver();
StorageMetadata storageMetadata = new StorageMetadata.Builder()
.setContentType(contentResolver.getType(imageUri))
.build();
FirebaseStorage.getInstance().getReference()
.child("users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child(UUID.randomUUID().toString())
.putStream(contentResolver.openInputStream(imageUri), storageMetadata)
.addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot task) {
Uri downloadUrl = task.getDownloadUrl();
Toast.makeText(getActivity(), R.string.image_successfully_uploaded, Toast.LENGTH_LONG).show();
}
})
.addOnFailureListener(getActivity(), new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(getActivity(), R.string.error_uploading_image, Toast.LENGTH_LONG).show();
}
});
} catch (IOException e) {
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}

Related

Attempting to implement a feature where a user can use their phone camera to take a picture and then it will be uploaded as their profile pic

I'm currently running into an issue with implementing a feature on my app where a user can take a picture using their phone's camera and then have it display as a bitmap image as well as be uploaded to Firebase.
I've seen several similar questions answered on here but nothing seems to be working for me, so I was hoping if someone could give my code a look and have insight for what I might be doing incorrectly.
My general process as of right now is that my "Choose from Gallery" option is working, but my "Take Photo" is not. When clicked in selectProfilePicOption(), I am able to take a picture and confirm it, but the data sent to onActivityResult() continues to get null. I want to be able to pass the taken photo and upload it as a Bitmap to my uploadImageToFirebase() function.
Thanks to all in advance for any assistance!
Here's my current code:
private void selectProfilePicOption(Context context){
final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose your profile picture");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if(options[which].equals("Take Photo")){
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, TAKE_IMAGE_REQUEST);
}else if(options[which].equals("Choose from Gallery")){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select image..."), PICK_IMAGE_REQUEST);
}else if(options[which].equals("Cancel")){
dialog.dismiss();
}
}
});
builder.show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_CANCELED) {
switch (requestCode) {
case TAKE_IMAGE_REQUEST:
if(resultCode == RESULT_OK){
data.getExtras().get("data");
File file = new File(Environment.getExternalStorageDirectory().getPath());
Uri uri = Uri.fromFile(file);
try{
System.out.println("attempting to store bitmap");
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
uploadImageToFirebase(bitmap);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
break;
case PICK_IMAGE_REQUEST:
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
uploadImageToFirebase(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
}
private void uploadImageToFirebase(final Bitmap bitmap){
if(filePath != null){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference ref = mStorageRef.child("images/ProfilePics/" + mUser.getUid());
ref.putFile(filePath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
profilePicture.setImageBitmap(bitmap);
Toast.makeText(SetProfileData.this, "Image Uploaded", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(SetProfileData.this, "Failed " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(#NonNull UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
progressDialog.setMessage("Uploaded " + (int)progress + "%");
}
});
}
}
The line data.getExtras().get("data"); contains the thumbnail of your captured image, but for some reasons, you are completely ignoring it.
Do it this way,
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_CANCELED) {
switch (requestCode) {
case TAKE_IMAGE_REQUEST:
if(resultCode == RESULT_OK){
Bitmap bitmap = (Bitmap) intent.getExtras().get("data") //this line is important
uploadImageToFirebase(bitmap);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
break;
case PICK_IMAGE_REQUEST:
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
uploadImageToFirebase(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
But beware the image thumbnail you received on onActivityResult() and uploaded to FireBase is not the full resolution image but just a compressed version of it. In order to get the full-size image, you can check out this

How to make image upload not just from camera?

I have three buttons in my application. One is for a camera, second is for a gallery and the third one is to upload. I changed my upload method from web server to googles firebase. Currently, I am only able to upload from my camera button. If I try to upload from gallery button it starts searching image in a temporary folder where images are saved when they are taken by a camera.
Taking image from gallery:
private void ImageSelection()
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, IMAGE_REQUEST);
}
On activity method:
else if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null)
{
Uri FilePath = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), FilePath);
mImageView.setImageBitmap(bitmap);
mImageView.setVisibility(View.VISIBLE);
mEditText.setVisibility(View.VISIBLE);
staticSpinner.setVisibility(View.VISIBLE);
if (TextUtils.isEmpty(mEditText.getText())){
mEditText.setError("Privalomas laukas");
}
} catch (IOException e) {
e.printStackTrace();
}
}
Upload method:
private void UploadImage() {
if(photoFile != null)
{
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference ref = storageReference.child("images/"+ staticSpinner.getSelectedItem().toString().trim()+"_"+ mEditText.getText().toString());
ref.putFile(Uri.fromFile(photoFile))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Uploaded", Toast.LENGTH_SHORT).show();
mImageView.setImageResource(0);
mImageView.setVisibility(View.GONE);
mEditText.setText("");
mEditText.setVisibility(View.GONE);
staticSpinner.setVisibility(View.GONE);
mCapture.setVisibility(View.VISIBLE);
mChoose.setVisibility(View.VISIBLE);
//mUpload.setVisibility(View.GONE);
photoFile = new File(String.valueOf(photoFile));
photoFile.delete();
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
mImageView.setImageResource(0);
mImageView.setVisibility(View.GONE);
mEditText.setText("");
mEditText.setVisibility(View.GONE);
staticSpinner.setVisibility(View.GONE);
mCapture.setVisibility(View.VISIBLE);
mChoose.setVisibility(View.VISIBLE);
//mUpload.setVisibility(View.GONE);
photoFile = new File(String.valueOf(photoFile));
photoFile.delete();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded "+(int)progress+"%");
}
});
}
}
Added an else if statement. Stupid me

video thumbnail of selected video while uploading on firebase storage

i am uploading video to firebase storage. i want to show the thumbnail of selected video on app screen
i have tried uploading image with the same code and it gives me the image preview of selected image, but it doesnot show any preview or thumbnail of selected video
moreover i want to know hoe to give the path of selected video as well..
main activity
public class MainActivity extends AppCompatActivity {
private static final int PICK_VIDEO_REQUEST = 3;
Button chooseImg, uploadImg;
ImageView imgView;
int PICK_IMAGE_REQUEST = 111;
Uri filePath;
ProgressDialog pd;
//creating reference to firebase storage
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://<<ur app url>>"); //change the url according to your firebase app
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chooseImg = (Button)findViewById(R.id.chooseImg);
uploadImg = (Button)findViewById(R.id.uploadImg);
imgView = (ImageView)findViewById(R.id.imgView);
pd = new ProgressDialog(this);
pd.setMessage("Uploading....");
chooseImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent, "Select Video"), PICK_VIDEO_REQUEST);
}
});
uploadImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(filePath != null) {
pd.show();
StorageReference childRef = storageRef.child("vide.mp4");
//uploading the image
UploadTask uploadTask = childRef.putFile(filePath);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
pd.dismiss();
Toast.makeText(MainActivity.this, "Upload successful", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
pd.dismiss();
Toast.makeText(MainActivity.this, "Upload Failed -> " + e, Toast.LENGTH_SHORT).show();
}
});
}
else {
Toast.makeText(MainActivity.this, "Select a video", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
//getting image from gallery
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting image to ImageView
imgView.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

Firebase Image Upload - Android

I am trying to upload Image to firebase storage but I am neither seeing the progress dialog nor the toast message.
The debug breakpoint is not even stopping at those lines.
Please help.
ib_profileImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent_modifyImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent_modifyImage);
}
});
}
//Image Capture Activity Result
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK){
progressDialog.setMessage("Uploading Image...");
progressDialog.show();
Uri uri = data.getData();
StorageReference filepath = storageReference_image.child("profile_photos").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(UserProfileActivity.this,"Upload Complete",Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
});
}
}
try this
public class MainActivity extends AppCompatActivity {
Button chooseImg, uploadImg;
ImageView imgView;
int PICK_IMAGE_REQUEST = 111;
Uri filePath;
ProgressDialog pd;
//creating reference to firebase storage
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-example-c4312.appspot.com"); //change the url according to your firebase app
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chooseImg = (Button)findViewById(R.id.chooseImg);
uploadImg = (Button)findViewById(R.id.uploadImg);
imgView = (ImageView)findViewById(R.id.imgView);
pd = new ProgressDialog(this);
pd.setMessage("Uploading....");
chooseImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent, "Select Image"), PICK_IMAGE_REQUEST);
}
});
uploadImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(filePath != null) {
pd.show();
StorageReference childRef = storageRef.child("image.jpg");
//uploading the image
UploadTask uploadTask = childRef.putFile(filePath);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
pd.dismiss();
Toast.makeText(MainActivity.this, "Upload successful", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
pd.dismiss();
Toast.makeText(MainActivity.this, "Upload Failed -> " + e, Toast.LENGTH_SHORT).show();
}
});
}
else {
Toast.makeText(MainActivity.this, "Select an image", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
//getting image from gallery
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting image to ImageView
imgView.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
don't forget to Change Rules in firebase console
By default we are not allowed to access firebase storage without authentication. To change it go to firebase console using any web browser. Open the firebase project that you have used in above steps and go to Storage and then Rules tab. Now change read and write rules to true as shown in below image.
try this method,its worked for me
Inside onActivityResult,
StorageReference storageRef = storage.getReferenceFromUrl(---STORAGE_BUCKET---);
StorageReference imagePathReference = storageRef.child("image");
final Uri uri = data.getData();
Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
// convert bitmap to byte array to save image in firebase storage
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (bmp != null) {
bmp.compress(Bitmap.CompressFormat.JPEG, 60, bos);
}
byte[] dataNew = bos.toByteArray();
uploadTask = imagePathReference.putBytes(dataNew);
try {
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// success
}
});
}catch (Exception e){
}

Android studio Firebase how to set a picture that a user selected from device storage as a user.PhotoURL

I have no experience in coding and i am just creating a app from tutorials in android studio. I have come a very long way in creating the app. I have implemented the code for selecting a image from the devive gallery and now i wonder how i can set that picture as a Firebase PhotoURL for the current user?
I have implemented that while I was trying firebase. Hope this would do your work.
getImageFromMobile is set to the onClick Method of ImageButton which I am using to set Image to.
public void getImageFromMobile(View view) {
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this,new String[]{
android.Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/");
startActivityForResult(intent , galleryRequestCode);
}
private void postDataToFirebase() {
mProgressDialog.setMessage("Posting the Blog to Firebase");
mProgressDialog.setCancelable(false);
final String titleValue = mPostTitle.getText().toString();
final String description = mPostDescription.getText().toString();
if((!TextUtils.isEmpty(titleValue))&& (!TextUtils.isEmpty(description)) && bitmap != null)
{
mProgressDialog.show();
StorageReference filePath = mStorage.child("Blog_Images").child(imagePathName);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, bytes);
String path = MediaStore.Images.Media.insertImage(PostActivity.this.getContentResolver(), bitmap, imagePathName, null);
Uri uri = Uri.parse(path);
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
DatabaseReference newPost = mDatabaseReference.push();
newPost.child("Title").setValue(titleValue);
newPost.child("Desc").setValue(description);
newPost.child("imageUrl").setValue(downloadUrl.toString());
Toast.makeText(PostActivity.this, "Data Posted Successfully to Firebase server", Toast.LENGTH_LONG).show();
mProgressDialog.dismiss();
Intent intent = new Intent(PostActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == galleryRequestCode && resultCode == RESULT_OK){
Uri imageUri = data.getData();
imagePathName = imageUri.getLastPathSegment();
Log.i("ImagePathName",imagePathName);
Toast.makeText(this, "ImagePathNameto be Checked" + imagePathName, Toast.LENGTH_SHORT).show();
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
imageButton.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Categories

Resources