0

I am newbie to native android development. I am working on android studio and developing an app with 3 tabs. 1 for map, 2nd is for camera and third is for displaying pictures that are taken in 2nd tab from camera. For this i saw many tutorials. But unfortunately i am unable to get any help from them. I have separate classes and layout for each of the tabs. I am able to save images into my sdcard.

Below is my code for camera

  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
  final View rootView = inflater.inflate(R.layout.camera, container, false);

    button = (Button)rootView.findViewById(R.id.getpicture);
    imageView = (ImageView)rootView.findViewById(R.id.imageView);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Check permission for CAMERA
            if (ActivityCompat.checkSelfPermission(getActivity(), CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {

                // Check Permissions Now
                // Callback onRequestPermissionsResult interceptado na Activity MainActivity
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{CAMERA},
                        Camera.REQUEST_CAMERA);

            }
            else {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE );

            }


        }
    });



    return rootView;
}

Method to save images

  private void SaveImage(Bitmap finalBitmap) {

    String root = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
    Log.v(getTag(), root);
    File myDir = new File(root + "/saved_images");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-" + n + ".jpg";
    File file = new File(myDir,fname);
    if (file.exists())file.delete();
    try {
        FileOutputStream out = new FileOutputStream(file);
        finalBitmap.compress(Bitmap.CompressFormat.JPEG,90,out);
        out.flush();
        out.close();


    } catch (Exception e) {
        e.printStackTrace();
    }
    //Toast.makeText(getContext(), "Image is saved", Toast.LENGTH_LONG).show();
}

Below is my Pictures tab class in which i want to show my images on slider

public class Pictures extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.pictures, container, false);

    return rootView;
}}

Note:

I need a image slider to show images saved in my sd card folder.

I am stuck to it almost a day and i am getting fed-up from it and i need help.

Any help will be highly appreciated.

Vadim Caen
  • 1,526
  • 11
  • 21
Moeez
  • 494
  • 9
  • 55
  • 147
  • Retrieve your all images from your `saved_images` folder which will return list of images in your `Pictures` fragment and use `ViewPager` for image sliding. – Piyush Feb 01 '17 at 12:14
  • @Piyush can you provide a tutorial for it ? – Moeez Feb 01 '17 at 12:17
  • Check [this](http://stackoverflow.com/questions/16557650/how-to-display-images-saved-in-sdcard-folder-in-android) and [this](http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/) – Piyush Feb 01 '17 at 12:22
  • @Piyush as for this [link](http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/), i did followed it but lost the path somewhere as at this tutorial `he` separated the code by classes `helper and adapters` and at `main activity` class all the adapters and helper are imported. So the constructors started to misbehave with each other. So i stopped going far in this. May be it's a better solution but i couldn't understand it. – Moeez Feb 01 '17 at 12:28

0 Answers0