精慕HU
为了将图像文件传递给 Android 广播接收器,您必须将文件转换为字节数组并使用putExtra方法发送intent.putExtra("myImage", convertBitmapToByteArray(bitmapImage));byte[] convertBitmapToByteArray(Bitmap bitmap) { ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); } finally { if (baos != null) { try { baos.close(); } catch (IOException e) { Log.e(BitmapUtils.class.getSimpleName(), "ByteArrayOutputStream was not closed"); } } }}然后您可以在广播接收器中转换回图像byte[] byteArray = intent.getByteArrayExtra("myImage");Bitmap myImage = convertCompressedByteArrayToBitmap(byteArray);Bitmap convertCompressedByteArrayToBitmap(byte[] src) { return BitmapFactory.decodeByteArray(src, 0, src.length);}