我正在尝试向服务发送捆绑包。这就是我呼叫服务的方式。
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
,我将上传到服务器。如何向服务发送位图?是什么导致了这个问题?
尝试像这样发送其行字节数组。
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);