В этом сценарии у меня есть два ImageViews, и моя проблема в том, что я могу загрузить сигнатурное изображение на мой Firebase, но не на изображение посетителей. Когда я попытался загрузить два ImageView на одну кнопку. .
вот мой код для MainActivity. xml
public class MainActivity extends AppCompatActivity {
EditText fullname, companyname, mobilenumber, emailaddress, salespersonnel, imagecaption;
TextView dateandtime;
Button buttonsave, buttonclear, buttoncapture, buttonsign, buttongetimage;
DatabaseReference reference;
Uri FilePathUri, FilePathUri2;
StorageReference storageReference, storageReference2b;
int Image_Request_Code = 7;
ProgressDialog progressDialog;
ImageView visitorimage, signatureimage;
Visitors visitors;
String pathtofile;
Calendar calander;
SimpleDateFormat simpledateformat;
String Date;
TextView DisplayDateTime;
private int requestcode;
private int resultcode;
private Intent data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
storageReference = FirebaseStorage.getInstance().getReference("Visitors Signature");
storageReference2b = FirebaseStorage.getInstance().getReference("Visitors Image");
progressDialog = new ProgressDialog(MainActivity.this);
fullname = (EditText) findViewById(R.id.full_name);
companyname = (EditText) findViewById(R.id.company_name);
mobilenumber = (EditText) findViewById(R.id.mobile_number);
emailaddress = (EditText) findViewById(R.id.email_address);
salespersonnel = (EditText) findViewById(R.id.sales_personnel);
imagecaption = (EditText) findViewById(R.id.image_caption);
dateandtime = (TextView) findViewById(R.id.time_date);
buttonsave = (Button) findViewById(R.id.btn_save);
buttoncapture = (Button) findViewById(R.id.btn_capture);
if (Build.VERSION.SDK_INT >= 23){
requestPermissions(new String[]{Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE},2);
}
buttonsign = (Button) findViewById(R.id.btn_getsign);
buttongetimage = (Button) findViewById(R.id.btn_getimage);
buttonclear = (Button) findViewById(R.id.btn_clear);
visitorimage = (ImageView) findViewById(R.id.visitor_image);
signatureimage = (ImageView) findViewById(R.id.image_view);
reference = FirebaseDatabase.getInstance().getReference().child("Visitors");
visitors = new Visitors();
String date_n = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.getDefault()).format(new
Date());
TextView date = (TextView) findViewById(R.id.time_date);
date.setText(date_n);
calander = Calendar.getInstance();
simpledateformat = new SimpleDateFormat("HH:mm:ss");
Date = simpledateformat.format(calander.getTime());
buttonsave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String full_name = fullname.getText().toString();
String company_name = companyname.getText().toString();
String mobile_number = mobilenumber.getText().toString();
String email_address = emailaddress.getText().toString();
String sales_personnel = salespersonnel.getText().toString();
String image_caption = imagecaption.getText().toString();
String time_date = dateandtime.getText().toString();
if (TextUtils.isEmpty(full_name)) {
Toast.makeText(MainActivity.this, "Please enter Full Name ",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(company_name)) {
Toast.makeText(MainActivity.this, "Please enter Company Name",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(mobile_number)) {
Toast.makeText(MainActivity.this, "Please enter Mobile Number ",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(email_address)) {
Toast.makeText(MainActivity.this, "Please enter Email Address ",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(sales_personnel)) {
Toast.makeText(MainActivity.this, "Please enter Sales Personnel ",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(image_caption)) {
Toast.makeText(MainActivity.this, "Please enter Image Caption ",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(time_date)) {
Toast.makeText(MainActivity.this, "Please enter time and date ",
Toast.LENGTH_LONG).show();
return;
}
UploadImage();
}
});
buttoncapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dispatchPictureTakerAction();
}
});
buttonclear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fullname.setText("");
companyname.setText("");
mobilenumber.setText("");
emailaddress.setText("");
salespersonnel.setText("");
imagecaption.setText("");
visitorimage.setImageBitmap(null);
signatureimage.setImageBitmap(null);
}
});
buttonsign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Signature.class);
startActivity(intent);
}
});
buttongetimage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Image"), Image_Request_Code);
}
});
}
private void dispatchPictureTakerAction() {
Intent takePic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePic.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
photoFile = createPhotoFile();
if(photoFile!=null) {
pathtofile = photoFile.getAbsolutePath();
Uri photoUri =
FileProvider.getUriForFile(MainActivity.this,"jcg.it.jcgvisitorsmonitoring.fileprovider", photoFile);
takePic.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(takePic, 1);
}
}
}//
private File createPhotoFile() {
String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = null;
try {
image = File.createTempFile(name, ".jpg", storageDir);
} catch (IOException e) {
Log.d("mylog", "Excep : " + e.toString());
}
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Image_Request_Code && resultCode == RESULT_OK && data != null &&
data.getData() != null) {
FilePathUri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), FilePathUri);
signatureimage.setImageBitmap(bitmap);
}
catch (IOException e) {
e.printStackTrace();
}
}
if (requestCode == Image_Request_Code && resultCode == RESULT_OK && data != null &&
data.getData() != null) {
FilePathUri2 = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), FilePathUri2);
visitorimage.setImageBitmap(bitmap);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public String GetFileExtension(Uri uri) {
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri)) ;
}
public void UploadImage() {
if (FilePathUri != null && pathtofile != null) {
progressDialog.setTitle("Visitor Data is Uploading....");
progressDialog.show();
StorageReference storageReference2 = storageReference.child(System.currentTimeMillis() + "."
+ GetFileExtension(FilePathUri));
storageReference2.putFile(FilePathUri).addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String TempImageName = imagecaption.getText().toString().trim();
String TempFullName = fullname.getText().toString().trim();
String TempCompanyName = companyname.getText().toString().trim();
String TempMobileNumber = mobilenumber.getText().toString().trim();
String TempEmailAddress = emailaddress.getText().toString().trim();
String TempSalesPersonnel = salespersonnel.getText().toString().trim();
String TempTimeandDate = dateandtime.getText().toString().trim();
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Visitor Logged Successfully!",
Toast.LENGTH_LONG).show();
String ImageUploadId = reference.push().getKey();
Intent intent = new Intent(MainActivity.this, Welcome.class);
startActivity(intent);
HashMap<String, Object> holder = new HashMap<>();
holder.put("Company Name" , TempCompanyName);
holder.put("Email Address" , TempEmailAddress);
holder.put("Full Name" , TempFullName);
holder.put("Mobile Number" , TempMobileNumber);
holder.put("Sales Personnel" , TempSalesPersonnel);
holder.put("Time and Date" , TempTimeandDate);
holder.put("Image URL" , taskSnapshot.getUploadSessionUri().toString());
holder.put("Caption" , TempImageName);
reference.child(ImageUploadId).updateChildren(holder);
}
}); //
}
else {
Toast.makeText(MainActivity.this, "Please Select Signature", Toast.LENGTH_LONG).show();
}
}
}