Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I used custom camera application then i open this app working fine but i open the camera view and take the picture get error Failed binder transaction in android 4.4 version but when i check in all version below than 4.4 was working fine. why there is problem in android 4.4 version?
My camera activity in below:
public class CameraActivity extends Activity {
Camera mCamera;
CameraPreview mCameraPreview;
protected static final int MEDIA_TYPE_IMAGE = 0;
static String FilePAth = "";
Button takePicture , btnGlr , btnCancelCamera;
static String base64string = "";
String ImageType;
final int RESULT_LOAD_IMAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.camera_preview);
mCamera = getCameraInstance();
mCameraPreview = new CameraPreview(CameraActivity.this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mCameraPreview);
takePicture = (Button) findViewById(R.id.btnTakePicture);
takePicture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mCamera.takePicture(null, null, mPicture);
Intent intent = getIntent();
if (intent.hasExtra("ImageType")) {
ImageType = getIntent().getStringExtra("ImageType").toString();
Log.v("log", " ImageType in Camera Activity -- > " + ImageType);
btnGlr = (Button)findViewById(R.id.btnGallary);
btnGlr.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE );
btnCancelCamera = (Button)findViewById(R.id.btnCancelCamera);
btnCancelCamera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplication(), MarketPlaceActivity.class);
startActivity(intent);
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
releaseCamera();
private void releaseCamera() {
if (mCamera != null) {
mCamera.release(); // release the camera for other applications
mCamera = null;
private Camera getCameraInstance() {
try {
Log.v("log_tag", "camera try:::" + mCamera);
mCamera = Camera.open();
} catch (Exception e) {
// cannot get camera or does not exist
Log.v("log_tag", "camera catch:::" + mCamera);
releaseCamera();
return mCamera;
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
if (ImageType.equals("AddPicture")) {
Intent i = new Intent(CameraActivity.this,MarketPlaceActivity.class);
i.putExtra("data", data);
startActivity(i);
} else {
Intent returnIntent = new Intent();
returnIntent.putExtra("data", data);
setResult(RESULT_OK, returnIntent);
CameraActivity.this.finish();
public void onBackPressed() {
Intent returnIntent = new Intent();
returnIntent.putExtra("path", FilePAth);
setResult(RESULT_OK, returnIntent);
finish();
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
Log.v("log"," picturePath --> selected Gallary Image path --> " + picturePath);
cursor.close();
InputStream iStream;
byte[] inputData = null;
try {
iStream = getContentResolver().openInputStream(selectedImage);
inputData = getBytes(iStream);
Log.v("log"," selected Gallary Image ByteArray --> " + inputData);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (ImageType.equals("AddPicture")) {
Intent i = new Intent(getBaseContext(),MarketPlaceActivity.class);
i.putExtra("data", inputData);
i.putExtra("image_from", "Gallary");
startActivity(i);
} else {
Intent returnIntent = new Intent();
returnIntent.putExtra("data", inputData);
returnIntent.putExtra("image_from", "Gallary");
setResult(RESULT_OK, returnIntent);
CameraActivity.this.finish();
// ImageView imageView = (ImageView) findViewById(R.id.imgView);
// imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
public byte[] getBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
return byteBuffer.toByteArray();
and camera preview below::
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder;
private Camera mCamera;
Boolean isPreviewRunning = true;
// Constructor that obtains context and camera
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mSurfaceHolder = getHolder();
mSurfaceHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
//mCamera.setDisplayOrientation(90);
} catch (IOException e) {
// left blank for now
/*@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
//mCamera.stopPreview();
// mCamera.release();
if (mCamera != null)
mCamera.stopPreview();
mCamera.release();
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
this.getHolder().removeCallback(this);
if (mCamera != null)
mCamera.stopPreview();
mCamera.release();
/*@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format,
int width, int height) {
// start preview with new settings
try {
mCamera.stopPreview();
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
//mCamera.setDisplayOrientation(90);
} catch (Exception e) {
// intentionally left blank for a test
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mSurfaceHolder.getSurface() == null){
// preview surface does not exist
return;
// stop preview before making changes
if(isPreviewRunning)
mCamera.stopPreview();
Parameters parameters = mCamera.getParameters();
WindowManager windo = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = windo.getDefaultDisplay();
if(display.getRotation() == Surface.ROTATION_0)
parameters.setPreviewSize(h,w);
mCamera.setDisplayOrientation(90);
if(display.getRotation() == Surface.ROTATION_90)
parameters.setPreviewSize(w, h);
if(display.getRotation() == Surface.ROTATION_180)
parameters.setPreviewSize(h, w);
// mCamera.setDisplayOrientation(270);
if(display.getRotation() == Surface.ROTATION_270)
parameters.setPreviewSize(w, h);
mCamera.setDisplayOrientation(180);
// set preview size and make any resize, rotate or
// reformatting changes here
// start preview with new settings
// mCamera.setParameters(parameters);
try {
mCamera.setPreviewDisplay(mSurfaceHolder);
mCamera.startPreview();
isPreviewRunning = true;
} catch (Exception e){
Log.d("log", "Error starting camera preview: " + e.getMessage());
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int previewWidth = MeasureSpec.getSize(widthSpec);
int previewHeight = MeasureSpec.getSize(heightSpec);
//Get the padding of the border background
int hPadding = getPaddingLeft() + getPaddingRight();
int vPadding = getPaddingTop() + getPaddingBottom();
//Resize the preview frame with correct aspect ratio
previewWidth += hPadding;
previewHeight -= vPadding;
//Add the padding of the border.
previewWidth += hPadding;
previewHeight += vPadding;
//Ask children to follow the new preview dimension
super.onMeasure(MeasureSpec.makeMeasureSpec(previewWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(previewHeight, MeasureSpec.EXACTLY));
and i set image in profile pic in image view in android my code in below::
public class ProfileFragment extends Fragment{
EditText edtFname ,edtLname ,edtEmailID ,edtPassword;
private String userId;
MyApplication app;
ImageView imgUser;
String base64st;
byte[] byteArrayimage;
CircularImageView imguser1;
ProgressDialog progress;
Bitmap resizedBitmap;
private View rootView;
Bitmap bmp;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.profile, container, false);
app = (MyApplication) getActivity().getApplicationContext();
edtFname = (EditText)rootView.findViewById(R.id.edtProfileFirstname);
edtLname = (EditText)rootView.findViewById(R.id.edtProfileLastname);
edtEmailID = (EditText)rootView.findViewById(R.id.edtProfileEmail);
edtPassword = (EditText)rootView.findViewById(R.id.edtProfilePAssword);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
progress = new ProgressDialog(getActivity());
progress.setMessage("Loading...");
new JSONTask().execute();
TextView btnTakeUserPhoto = (TextView)rootView.findViewById(R.id.txt_change_profile);
btnTakeUserPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraAct = new Intent(getActivity(),CameraActivity.class);
cameraAct.putExtra("ImageType", "ProfilePicture");
startActivityForResult(cameraAct, 1);
Button btnUpdateProfile = (Button)rootView.findViewById(R.id.btn_update_profile);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),
"fonts/ITCAvantGardeStd-BkCn.otf");
edtFname.setTypeface(tf);
edtLname.setTypeface(tf);
edtEmailID.setTypeface(tf);
edtPassword.setTypeface(tf);
btnTakeUserPhoto.setTypeface(tf);
btnUpdateProfile.setTypeface(tf);
btnUpdateProfile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String strFname = edtFname.getText().toString();
String strLname = edtLname.getText().toString();
String strEmail = edtEmailID.getText().toString();
String strPassword = edtPassword.getText().toString();
Log.v("log", " strPassword " + strPassword);
ArrayList<UserInfo_dto> result_list = DBAdpter.updateUserInfo(userId,strFname,strLname,strEmail,strPassword,base64st);
if(result_list.get(0).getMsg().equals("User information successfully updated"))
Toast.makeText(getActivity(), result_list.get(0).getMsg() , 1).show();
String message = DBAdpter.updateUserImage(userId,base64st);
Log.v("log"," message --> "+ message);
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm
.beginTransaction();
HomeFragment fm2 = new HomeFragment();
fragmentTransaction.replace(R.id.relProfileFraLayout,fm2, "HELLO");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
return rootView;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
Log.v("log"," OnActivity Result");
if (data.hasExtra("data")) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true; // inPurgeable is used to free up
// memory while required
Bitmap b = BitmapFactory.decodeByteArray(
data.getByteArrayExtra("data"), 0,
data.getByteArrayExtra("data").length, options);
int width = b.getWidth();
int height = b.getHeight();
int newWidth = 100;
int newHeight = 80;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
if (data.hasExtra("image_from")) {
resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height,
matrix, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byteArrayimage = stream.toByteArray();
int rotation = getActivity().getWindowManager()
.getDefaultDisplay().getRotation();
int finalDegree = 0;
if (rotation == 0) {
finalDegree = 90;
if (rotation == 1) {
finalDegree = 270;
if (rotation == 2) {
finalDegree = 180;
if (rotation == 3) {
finalDegree = 90;
matrix.postRotate(finalDegree);
resizedBitmap = Bitmap.createBitmap(b, 0, 0, width,
height, matrix, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byteArrayimage = stream.toByteArray();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
imguser1.setImageBitmap(resizedBitmap);
imguser1.setScaleType(ScaleType.CENTER);
imguser1.setBorderColor(getResources().getColor(R.color.GrayLight));
imguser1.setBorderWidth(0);
MarketPlaceActivity.imView.setImageBitmap(resizedBitmap);
MarketPlaceActivity.imView.setScaleType(ScaleType.CENTER);
} else {
imgUser.setImageBitmap(resizedBitmap);
imgUser.setScaleType(ScaleType.CENTER);
MarketPlaceActivity.imView1.setImageBitmap(resizedBitmap);
MarketPlaceActivity.imView1.setScaleType(ScaleType.CENTER);
base64st = Base64.encodeBytes(byteArrayimage);
public class JSONTask extends AsyncTask<String, Void, String> {
public void onPreExecute() {
progress.show();
@Override
protected String doInBackground(String... arg) {
String listSize = "";
String FirstNAme = DBAdpter.fetch_UserDetail_data.get(0).getFirst_name();
userId = app.getUserID();
String lastName = DBAdpter.fetch_UserDetail_data.get(0).getLast_name();
String emailId = DBAdpter.fetch_UserDetail_data.get(0).getEmail();
String Mobile = DBAdpter.fetch_UserDetail_data.get(0).getMobile();
Log.v("log", "userId" + userId + " FirstNAme : " + FirstNAme + " LAstName " + lastName + " emailId " + emailId + "Mobile " + Mobile);
edtFname.setText(FirstNAme);
edtLname.setText(lastName);
edtEmailID.setText(emailId);
edtPassword.setText("");
String img_url = DBAdpter.fetch_UserDetail_data.get(0).getStrore_profile_image().toString().trim();
bmp = getBitmapFromUrl(img_url);
return listSize; // This value will be returned to your
// onPostExecute(result) method
@Override
protected void onPostExecute(String result) {
// Create here your JSONObject...
Log.v("log_tag", "list ON Post");
progress.dismiss();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.v("log", " Above HoneyComb ");
imguser1 = (CircularImageView) rootView.findViewById(R.id.img_user_image);
imguser1.setImageBitmap(bmp);
imguser1.setBorderColor(getResources().getColor(R.color.GrayLight));
imguser1.setBorderWidth(0);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imguser1
.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byte[] byteArray = stream.toByteArray();
base64st = Base64.encodeBytes(byteArray);
Log.v("log_tag", "base64st" + base64st);
} else {
Log.v("log", " Below HoneyComb ");
imgUser = (ImageView)rootView.findViewById(R.id.img_user_image);
imgUser.setImageBitmap(bmp);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imgUser
.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byte[] byteArray = stream.toByteArray();
base64st = Base64.encodeBytes(byteArray);
Log.v("log_tag", "base64st" + base64st);
// You'll have to override this method on your other tasks that extend
// from this one and use your JSONObject as needed
public Bitmap getBitmapFromUrl(String urlStore) {
URL url = null;
try {
url = new URL(urlStore);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection()
.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return bmp;
I test Android 4.4 version then get error here::
04-30 10:34:39.303: V/log(32387): onMenuItemClick Selected Item ===> Add Picture
04-30 10:34:39.353: V/log(32387): current state is visible
04-30 10:34:39.414: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:39.414: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:39.414: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:39.424: W/ApplicationPackageManager(32387): getCSCPackageItemText()
04-30 10:34:39.444: V/log_tag(32387): camera try:::null
04-30 10:34:39.744: V/log(32387): ImageType in Camera Activity -- > AddPicture
04-30 10:34:41.065: V/log(32387): hiding menu
04-30 10:34:41.065: I/Choreographer(32387): Skipped 78 frames! The application may be doing too much work on its main thread.
04-30 10:34:41.295: D/AbsListView(32387): onVisibilityChanged() is called, visibility : 4
04-30 10:34:41.295: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:41.295: D/AbsListView(32387): onVisibilityChanged() is called, visibility : 4
04-30 10:34:41.295: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:41.295: D/AbsListView(32387): onVisibilityChanged() is called, visibility : 4
04-30 10:34:41.295: D/AbsListView(32387): unregisterIRListener() is called
04-30 10:34:53.207: D/dalvikvm(32387): GC_FOR_ALLOC freed 484K, 6% free 37240K/39444K, paused 32ms, total 32ms
04-30 10:34:53.247: E/JavaBinder(32387): !!! FAILED BINDER TRANSACTION !!!
04-30 10:35:20.444: D/AndroidRuntime(32387): Shutting down VM
04-30 10:35:20.444: W/dalvikvm(32387): threadid=1: thread exiting with uncaught exception (group=0x4192eda0)
04-30 10:35:20.454: E/AndroidRuntime(32387): FATAL EXCEPTION: main
04-30 10:35:20.454: E/AndroidRuntime(32387): Process: com.buymysari, PID: 32387
04-30 10:35:20.454: E/AndroidRuntime(32387): java.lang.RuntimeException: takePicture failed
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.hardware.Camera.native_takePicture(Native Method)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.hardware.Camera.takePicture(Camera.java:1338)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.hardware.Camera.takePicture(Camera.java:1283)
04-30 10:35:20.454: E/AndroidRuntime(32387): at com.buymysari.CameraActivity$2.onClick(CameraActivity.java:58)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.view.View.performClick(View.java:4633)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.view.View$PerformClick.run(View.java:19330)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.os.Handler.handleCallback(Handler.java:733)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.os.Handler.dispatchMessage(Handler.java:95)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.os.Looper.loop(Looper.java:157)
04-30 10:35:20.454: E/AndroidRuntime(32387): at android.app.ActivityThread.main(ActivityThread.java:5356)
04-30 10:35:20.454: E/AndroidRuntime(32387): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 10:35:20.454: E/AndroidRuntime(32387): at java.lang.reflect.Method.invoke(Method.java:515)
04-30 10:35:20.454: E/AndroidRuntime(32387): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
04-30 10:35:20.454: E/AndroidRuntime(32387): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
04-30 10:35:20.454: E/AndroidRuntime(32387): at dalvik.system.NativeStart.main(Native Method)
04-30 10:35:26.159: I/Process(32387): Sending signal. PID: 32387 SIG: 9
04-30 10:35:26.489: W/ActivityThread(844): Application com.buymysari can be debugged on port 8100...
04-30 10:35:26.509: W/ApplicationPackageManager(844): getCSCPackageItemText()
04-30 10:35:26.670: D/AbsListView(844): Get MotionRecognitionManager
04-30 10:35:26.700: D/AbsListView(844): Get MotionRecognitionManager
04-30 10:35:26.720: V/log(844): UserID null
04-30 10:35:26.720: V/log(844): StoreID null
04-30 10:35:26.730: V/log(844): UserID store_id --> 5
04-30 10:35:26.730: D/AndroidRuntime(844): Shutting down VM
–
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
if (ImageType.equals("AddPicture")) {
Intent i = new Intent(CameraActivity.this,MarketPlaceActivity.class);
i.putExtra("data", data);// problem lies here
startActivity(i);
} else {
Intent returnIntent = new Intent();
returnIntent.putExtra("data", data);// problem lies here
setResult(RESULT_OK, returnIntent);
CameraActivity.this.finish();
you are trying to parse large data along with intent but as per the documentation, the Binder transaction failed because it was too large.
Solution :
I would suggest you to create bitmap from the received byte[] data
and store the image on device.then just parse the path of that image to any other activity according to your requirement.
In my case it was image byte array which was getting passed along with other variables in intent bundle extra and its size was way too large, hence it caused TransactionTooLargeException.
Solution: Either store image byte array on external storage and don't pass in extras of intent bundle.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.