我有问题。我正在使用后端firebase制作应用程序,我想将图像保存在firebase中。有没有办法在Firebase中存储位图图像。我没有得到正确的教程..请帮助。
这里是我获取图片并希望在Firebase中保存图片的代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
f = temp;
break;
}
}
try {
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),
bitmapOptions);
mImageCapture.setImageBitmap(bitmap);
mTextImage.setVisibility(View.GONE);
String path = android.os.Environment
.getExternalStorageDirectory()
+ File.separator
+ "Phoenix" + File.separator + "default";
f.delete();
OutputStream outFile = null;
File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
try {
outFile = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
outFile.flush();
outFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == 2) {
Uri selectedImage = data.getData();
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
mImageCapture.setImageBitmap(thumbnail);
mTextImage.setVisibility(View.GONE);
}
}
}
这是我在Firebase中保存姓名,电话号码和位置的代码
if(isOnline()){
User myData = new User();
myData.setUsername(name);
myData.setPhoneno(phone);
myData.setLocation(location);
ref.child("DataBase").push().setValue(myData);
Toast.makeText(BasicInformation.this, "Data saved", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(BasicInformation.this, HomePage.class);
startActivity(intent);
finish();
}else{
openDialog();
}