1

我正在尝试将捆绑包发送到服务。这就是我调用服务的方式。

1)    Bundle bundle = new Bundle();
2)    bundle.putParcelable("bitmap", bmp);       //    <--- problem
3)    bundle.putString("type", "SingleImage");

4)    Intent intent = new Intent(getApplicationContext(),SyncService.class);
5)    intent.putExtra("imageUploadBundle", bundle);
6)    startService(intent);

当我评论line 2服务被调用。但是,如果我不评论该行,则不会调用该服务。我想发送一个bitmap to the service我将上传到服务器的文件。如何将位图发送到服务?是什么导致了这个问题?

4

1 回答 1

2

尝试像这样发送它的行字节数组。

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Bundle bundle = new Bundle();
bundle.putByteArray("bitmap", byteArray);
bundle.putString("type", "SingleImage");

Intent intent = new Intent(getApplicationContext(),SyncService.class);
intent.putExtra("imageUploadBundle", bundle);
startService(intent);
于 2013-06-27T07:54:38.097 回答