Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FireBase Declaration
- FirebaseDatabase database;
- DatabaseReference myRef;
- FirebaseStorage storage;
- StorageReference storageRef, imagesRef, imageNameWithPathRef;
- onCreate(){
- // FireBase Initialization
- storage = FirebaseStorage.getInstance();
- storageRef = storage.getReference();
- // Create a child reference
- // imagesRef now points to "images"
- imagesRef = storageRef.child("CustomerImage");
- // Child references can also take paths
- // spaceRef now points to "users/me/profile.png
- // imagesRef still points to "images"
- imageNameWithPathRef = storageRef.child("CustomerImage/" + getCurrentTimeStamp() + ".jpg");
- // Reference's path is: "images/space.jpg"
- // This is analogous to a file path on disk
- imageNameWithPathRef.getPath();
- // Reference's name is the last segment of the full path: "space.jpg"
- // This is analogous to the file name
- imageNameWithPathRef.getName();
- // Reference's bucket is the name of the storage bucket that the files are stored in
- imageNameWithPathRef.getBucket();
- /**
- * Get the FireBase DB Object
- * Get the reference for the Customer table
- * Used Upload task to save the Customer details
- */
- database = FirebaseDatabase.getInstance();
- myRef = database.getReference("Customer");
- mProgressDialog.show();
- if (null != byteData) {
- UploadTask uploadTask = imageNameWithPathRef.putBytes(byteData);
- uploadTask.addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception exception) {
- // Handle unsuccessful uploads
- exception.printStackTrace();
- Log.e("Failed to image upload:", String.valueOf(exception) + "");
- mProgressDialog.dismiss();
- }
- }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
- @Override
- public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
- mProgressDialog.dismiss();
- // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
- Uri downloadUrl = taskSnapshot.getDownloadUrl();
- Log.e("downloadUrl", downloadUrl.getPath());
- Customer mCustomer = new Customer();
- int id = Integer.parseInt(NewId) + 1;
- mCustomer.setId(String.valueOf(id));
- mCustomer.setname(name);
- mCustomer.setphone(phone);
- mCustomer.setaddress(address);
- mCustomer.setage(age);
- mCustomer.setexperience(experience);
- mCustomer.setratings(rating);
- mCustomer.setImagePath(imageNameWithPathRef.getPath());
- mCustomer.setadded_by_userid(UserId);
- mCustomer.setadded_by_username(UserName);
- myRef.child(String.valueOf(id)).setValue(mCustomer);
- finish();
- }
- });
- } else {
- Customer mCustomer = new Customer();
- int id = Integer.parseInt(NewId) + 1;
- mCustomer.setId(String.valueOf(id));
- mCustomer.setname(name);
- mCustomer.setphone(phone);
- mCustomer.setaddress(address);
- mCustomer.setage(age);
- mCustomer.setexperience(experience);
- mCustomer.setratings(rating);
- mCustomer.setImagePath("");
- mCustomer.setadded_by_userid(UserId);
- mCustomer.setadded_by_username(UserName);
- myRef.child(String.valueOf(id)).setValue(mCustomer);
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement