我的活动中有一个方法可以启动 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;
}
}
}
一切正常,但图像也存储在设备的图库中。
我该如何防止这种情况或我做错了什么?