3

我的活动中有一个方法可以启动 image_capture 事件

    public static void takePhoto(boolean fullSize) {

    if(isIntentAvailable(mActivity.getApplicationContext(), MediaStore.ACTION_IMAGE_CAPTURE)){
        mActivity.startActivityForResult(new Intent(
                MediaStore.ACTION_IMAGE_CAPTURE), CAPTURE_IMAGE);
    }
    else{
        Toast.makeText(mActivity.getApplicationContext(), "Geen camera beschikbaar", Toast.LENGTH_SHORT).show();
    }
}

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
            packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

当用户拍照时,我想从照片中获取字节并广播这些字节。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_CANCELED) {

        case CAPTURE_IMAGE:
                byte[] photoBytes = null;

                if (data != null) {
                    Bitmap b = (Bitmap) data.getExtras().get("data");
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    b.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    photoBytes = stream.toByteArray();

                    Toast.makeText(getApplicationContext(), "Foto wordt geupload..", Toast.LENGTH_SHORT).show();
                    Log.d("ShowScreenActivity", Integer.toString(photoBytes.length));

                    // Send bytearray back to server
                    BroadcastSender.sendPicture(photoBytes);
                }
                else
                    Log.d("ShowScreenActivity", "Data in intent is empty");

            break;
        }
    }
}

一切正常,但图像也存储在设备的图库中。
我该如何防止这种情况或我做错了什么?

4

2 回答 2

3

您的图像将保存到图库,因为这是默认行为。要覆盖它,您需要指定一个不同的目标文件夹来保存您的图像(在调用相机的意图中),并在该文件夹中放置一个 .nomedia 文件

于 2012-09-20T11:36:27.587 回答
0

您是否将图片临时存储在 BroadcastSender 的 sendPicture 方法的目录中?

如果图像存储在 MediaScanner 索引的目录中,它将自动添加到图库中。

于 2012-09-20T11:57:11.987 回答