我的活动中有一个方法可以启动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;
}
}
}
一切正常,但图像也存储在设备的图库中 我怎样才能防止这种情况或我做错了什么?
答案 0 :(得分:2)
您的图片已保存到图库,因为这是默认行为。要覆盖它,您需要指定一个不同的目标文件夹来保存图像(在调用摄像头的意图中),并将.nomedia文件放在文件夹中
答案 1 :(得分:0)
您是否将图片临时存储在BroadcastSender的sendPicture方法的目录中?
如果图像存储在MediaScanner索引的目录中,它将自动添加到图库中。