android - 如何获取捕获的图像文件路径并保存到数据库?

标签 android

我想知道是否有人可以帮助我,我的应用程序当前使用多个捕获图像按钮拍照,我想获取每张图像的文件路径并将其保存到数据库中。我将如何去做这件事。我尝试使用 string name = fileuri.getpath 将它保存到我的数据库中,但这并没有给出拍摄图像的确切目的地。

else if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE_2) {

             if (resultCode == RESULT_OK) {

                String second_imagePath = fileUri.getPath();
                 BitmapFactory.Options options = new BitmapFactory.Options();
                 // down sizing image as it throws OutOfMemory Exception for larger
                 // images
                 options.inSampleSize = 8;
                 final Bitmap bitmap = BitmapFactory.decodeFile(second_imagePath, options);
                 second_image.setImageBitmap(bitmap);

                 Toast.makeText(getApplicationContext(),
                         second_imagePath, Toast.LENGTH_SHORT)
                         .show();

最佳答案

有几个步骤你需要遵循,你需要在打开 Intent 之前传递图像名称

 String fileName = "some.jpg";  
 ContentValues values = new ContentValues();  
 values.put(MediaStore.Images.Media.TITLE, fileName);  
 mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
 intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);  
 startActivityForResult(intent, CAPTURE_PICTURE_INTENT);

然后 onActivityResult()

Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
cursor.moveToFirst(); 
String capturedImageFilePath = cursor.getString(column_index_data);

关于android - 如何获取捕获的图像文件路径并保存到数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789402/

相关文章:

android - 如何从任务管理器中杀死Android应用程序?

android - 如何更改Android软键盘中任意键的键背景

Android:尝试获取 AppBarLayout LayoutParams 时应用程序崩溃

android - Samsung Galaxy S adb 驱动程序详细信息?

java - Android:闲置 X 分钟后重新打开应用程序?

android - 如何在没有 SuperSU 的情况下授予 root 访问权限

java - Android 从一个应用程序转移到另一个应用程序

java.sql.SQLException : Single-Sign-On is only supported on Windows. 请指定用户名

android - 按 Enter 键时搜索 Activity 未启动

android - Google Play 计费 API : How to understand the user is subscribed?