0

有没有办法从以下ActivityResult方法获取图像ID?

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if(requestCode == IMAGE_CAPTURE){
            if(resultCode == RESULT_OK){
                try{
                    Bitmap b1 = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);

                    System.out.println("GGEGEGGEGEGEGGEGEGEGEG" + imageUri.getPath());
//                   Intent i2 = new Intent(Intent.ACTION_VIEW, imageUri);
//                   startActivity(i2);
                }
                catch(FileNotFoundException e ){
                    System.out.println("OnActivityResult hat einen Fehler geworfen");
                } catch (IOException e) {
                    System.out.println("ONACTIVITYRESULT hat einen Fehler geworfen");
                }
            }
        }
    }

我需要它来获取某个图像的缩略图。

编辑:我像这样捕捉图像:

private void takePic() {
        ContentValues values = new ContentValues();
        String TITLE = null;
        values.put(MediaColumns.TITLE, TITLE);
        String DESCRIPTION  = null;
        long id = (Long) null;
        values.put(ImageColumns.DESCRIPTION, DESCRIPTION);
        values.put(MediaColumns.MIME_TYPE, "image/jpeg");
        values.put(MediaColumns._ID, id);
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);


        System.out.println("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVvv" + imageUri.getPath());
        startActivityForResult(intent, IMAGE_CAPTURE);


    }
4

1 回答 1

0

创建 后imageUri,您可以像这样从中获取 ID:

    String[] columns = {MediaColumns._ID}; 
    Cursor cursor =  getContentResolver().query(imageUri, columns, null, null, null); 
    cursor.moveToFirst(); 
    long id = cursor.getLong(0);

注意:您可能应该从代码中删除此行,takePic()因为行 ID 是由内容提供者为您创建的:

    values.put(MediaColumns._ID, id);
于 2013-05-21T17:45:20.820 回答