Hi

I have started camera using startActivityForResult() from my PhotosFragment
and decode the image and display on grid view on fragment using adapter. It
captures image and onActvityResult called properly and all code on
onActvityResult works fine(find through debug).But I need to display the
camera taken image on gridview on fragment.After taking picture and save,it
goes to Photofragment onActivityResult,and then go to home fragment
directly(I have loaded HomeFragment and PhotosFragment on MainActivity).Not
displayed It ocurs only on Samsung S4 device only.

I have tried by changing config parameter of Activity in manifest.But not
works for me.

*Reference:*

Android: Activity getting Destroyed after calling Camera Intent
<http://stackoverflow.com/questions/16014930/android-activity-getting-destroyed-after-calling-camera-intent>

http://stackoverflow.com/a/10411504

*PhotosFragment.java*

private void selectImage() {
        final CharSequence[] items = {"Take Photo", "Choose from Library",
                "Cancel"};

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Add Photo");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int item) {
                if (items[item].equals("Take Photo")) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File f = new File(android.os.Environment
                            .getExternalStorageDirectory(), "temp.jpg");
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                    startActivityForResult(intent, REQUEST_CAMERA);
                } else if (items[item].equals("Choose from Library")) {
                    Intent intent = new Intent(
                            Intent.ACTION_PICK,

android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(
                            Intent.createChooser(intent, "Select File"),
                            SELECT_FILE);
                } else if (items[item].equals("Cancel")) {
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }



    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        //super.onActivityResult(requestCode,resultCode,data);
        Log.i("CameraResult","requestCode->"+requestCode+"where
REQUEST_CAMERA->"+REQUEST_CAMERA);
        Log.i("CameraResult","resultCode->"+resultCode+"where
getActivity().RESULT_OK->"+getActivity().RESULT_OK);
        Log.i("CameraResult","data->"+data);

        if (resultCode == getActivity().RESULT_OK) {
            int thumbFactor = 6; // choose a power of 2

            if (requestCode == REQUEST_CAMERA) {
                File f = new File(Environment.getExternalStorageDirectory()
                        .toString());
                for (File temp : f.listFiles()) {
                    if (temp.getName().equals("temp.jpg")) {
                        f = temp;
                        break;
                    }
                }


Log.i("CameraResult","f.getAbsolutePath()->"+f.getAbsolutePath());
                try {

                    imagePaths.add(f.getAbsolutePath());

                    //CarPicturesAdapter adapter = new
CarPicturesAdapter(getActivity().getBaseContext(), R.id.pictureGrid,
images);

                    CarPicturesAdapter adapter = new
CarPicturesAdapter(getActivity().getBaseContext(), R.id.pictureGrid,
imagePaths);
                    contentImage.setAdapter(adapter);

                    Log.i("CameraResult", "set adapter");

                    f.delete();

                    Log.i("CameraResult", "file deleted");
                } catch (Exception e) {
                    e.printStackTrace();
                }

                //super.onActivityResult(requestCode,resultCode,data);
            }
            /*else{
                super.onActivityResult(requestCode,resultCode,data);
            }*/
        }
    }

*CarPicturesAdapter.java*

public class CarPicturesAdapter extends ArrayAdapter<String>{

    private SparseBooleanArray mSelectedItemsIds;
    private final ArrayList<String> objects;
    private Context context;
    private String[] images;

    public CarPicturesAdapter(Context context, int textViewResourceId,
                           ArrayList<String> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        this.images = new String[objects.size()];
        objects.toArray(this.images);
        this.objects = objects;
        mSelectedItemsIds = new SparseBooleanArray();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        CheckableLayout checkableLayout = new CheckableLayout(context);
        View rowView =
inflater.inflate(R.layout.picture_item_gridview, parent, false);

        SquareImageView imageView = (SquareImageView)
rowView.findViewById(R.id.car_image);

        //imageView.setImageBitmap(Image.getBitmap(images[position]));

        ImageLoader.getInstance().displayImage(String.valueOf(Uri.fromFile(new
File(images[position]))), imageView);

        checkableLayout.addView(rowView);
        return checkableLayout;
    }

    @Override
    public void remove(String image) {
        objects.remove(image);
        notifyDataSetChanged();
    }

    public void toggleSelection(int position) {
        selectView(position, !mSelectedItemsIds.get(position));
    }

    public void removeSelection() {
        mSelectedItemsIds = new SparseBooleanArray();
        notifyDataSetChanged();
    }

    public void selectView(int position, boolean value) {
        if (value)
            mSelectedItemsIds.put(position, value);
        else
            mSelectedItemsIds.delete(position);
        notifyDataSetChanged();
    }

    public int getSelectedCount() {
        return mSelectedItemsIds.size();
    }

    public SparseBooleanArray getSelectedIds() {
        return mSelectedItemsIds;
    }

    public class CheckableLayout extends FrameLayout implements Checkable {
        private boolean mChecked;

        public CheckableLayout(Context context) {
            super(context);
        }



-- 
by

*R.RAMPRASAD*

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to