我想创建Android应用程序拍照然后我们可以用编辑文本视图做一些评论,当我点击发送按钮时,图片和评论将出现在数据库中(所以我们可以使用笔记本电脑看数据库的结果)
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以使用以下代码捕获图像:
public void captureImage() {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
android.Manifest.permission.CAMERA
}, 6);
}
return;
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 6:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
captureImage();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uploading.show();
if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {
bitmap = (Bitmap) data.getExtras().get("data");
} else if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
}
if (bitmap != null) {
toStringImage(bitmap); //this function will convert image into Base64 string
} else {
uploading.dismiss();
}
}
在GitHub上检查相同的代码: captureImage
现在,要将此图像上传到数据库:
检查this answer如何将图像上传到数据库。