Skip to content Skip to sidebar Skip to footer

Does Whatsapp Uses The Native Gallery While Sharing Images

I am wondering if WhatsApp uses the native Android gallery or its own custom gallery. Basically this gallery allows the user to select multiple images. But I don't seem to find any

Solution 1:

I have created my custom gallery to do so.

Try this is working like charm

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;


import com.ijoomer.src.R;

/**
 * This Class Contains All Method Related To IjoomerPhotoGalaryActivity.
 * 
 * @author tasol
 * 
 */publicclassIjoomerPhotoGalaryActivityextendsActivity {

    private ImageAdapter imageAdapter;

    private String[] arrPath;
    privateboolean[] thumbnailsselection;
    privateint ids[];
    privateint count;


    /**
     * Overrides methods
     */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_gallery);

        final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
        finalStringorderBy= MediaStore.Images.Media._ID;
        @SuppressWarnings("deprecation")Cursorimagecursor= managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
        intimage_column_index= imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
        this.count = imagecursor.getCount();
        this.arrPath = newString[this.count];
        ids = newint[count];
        this.thumbnailsselection = newboolean[this.count];
        for (inti=0; i < this.count; i++) {
            imagecursor.moveToPosition(i);
            ids[i] = imagecursor.getInt(image_column_index);
            intdataColumnIndex= imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            arrPath[i] = imagecursor.getString(dataColumnIndex);
        }
        GridViewimagegrid= (GridView) findViewById(R.id.PhoneImageGrid);
        imageAdapter = newImageAdapter();
        imagegrid.setAdapter(imageAdapter);
        imagecursor.close();

        finalButtonselectBtn= (Button) findViewById(R.id.selectBtn);
        selectBtn.setOnClickListener(newOnClickListener() {

            publicvoidonClick(View v) {
                finalintlen= thumbnailsselection.length;
                intcnt=0;
                StringselectImages="";
                for (inti=0; i < len; i++) {
                    if (thumbnailsselection[i]) {
                        cnt++;
                        selectImages = selectImages + arrPath[i] + "|";
                    }
                }
                if (cnt == 0) {
                    Toast.makeText(getApplicationContext(), "Please select at least one image", Toast.LENGTH_LONG).show();
                } else {

                    Log.d("SelectedImages", selectImages);
                    Intenti=newIntent();
                    i.putExtra("data", selectImages);
                    setResult(Activity.RESULT_OK, i);
                    finish();
                }
            }
        });
    }
    @OverridepublicvoidonBackPressed() {
        setResult(Activity.RESULT_CANCELED);
        super.onBackPressed();

    }

    /**
     * Class method
     *//**
     * This method used to set bitmap.
     * @param iv represented ImageView 
     * @param id represented id
     */privatevoidsetBitmap(final ImageView iv, finalint id) {

        newAsyncTask<Void, Void, Bitmap>() {

            @Overrideprotected Bitmap doInBackground(Void... params) {

                return MediaStore.Images.Thumbnails.getThumbnail(getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
            }

            @OverrideprotectedvoidonPostExecute(Bitmap result) {
                super.onPostExecute(result);
                iv.setImageBitmap(result);
            }
        }.execute();
    }


    /**
     * List adapter
     * @author tasol
     */publicclassImageAdapterextendsBaseAdapter {
        private LayoutInflater mInflater;

        publicImageAdapter() {
            mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        publicintgetCount() {
            return count;
        }

        public Object getItem(int position) {
            return position;
        }

        publiclonggetItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if (convertView == null) {
                holder = newViewHolder();
                convertView = mInflater.inflate(R.layout.photo_gallery_item, null);
                holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage);
                holder.IjoomerCheckBox = (IjoomerCheckBox) convertView.findViewById(R.id.itemCheckBox);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.IjoomerCheckBox.setId(position);
            holder.imageview.setId(position);
            holder.IjoomerCheckBox.setOnClickListener(newOnClickListener() {

                publicvoidonClick(View v) {
                    IjoomerCheckBoxcb= (IjoomerCheckBox) v;
                    intid= cb.getId();
                    if (thumbnailsselection[id]) {
                        cb.setChecked(false);
                        thumbnailsselection[id] = false;
                    } else {
                        cb.setChecked(true);
                        thumbnailsselection[id] = true;
                    }
                }
            });
            holder.imageview.setOnClickListener(newOnClickListener() {

                publicvoidonClick(View v) {
                    intid= holder.IjoomerCheckBox.getId();
                    if (thumbnailsselection[id]) {
                        holder.IjoomerCheckBox.setChecked(false);
                        thumbnailsselection[id] = false;
                    } else {
                        holder.IjoomerCheckBox.setChecked(true);
                        thumbnailsselection[id] = true;
                    }
                }
            });
            try {
                setBitmap(holder.imageview, ids[position]);
            } catch (Throwable e) {
            }
            holder.IjoomerCheckBox.setChecked(thumbnailsselection[position]);
            holder.id = position;
            return convertView;
        }
    }


    /**
     * Inner class
     * @author tasol
     */classViewHolder {
        ImageView imageview;
        IjoomerCheckBox IjoomerCheckBox;
        int id;
    }

}

photo_gallery.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/selectBtn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Select"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:minWidth="200px" /><GridViewandroid:id="@+id/PhoneImageGrid"android:layout_width="match_parent"android:layout_height="match_parent"android:numColumns="auto_fit"android:verticalSpacing="10dp"android:horizontalSpacing="10dp"android:columnWidth="90dp"android:stretchMode="columnWidth"android:gravity="center"android:layout_above="@id/selectBtn" /></RelativeLayout>

photo_gallery_item.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><ImageViewandroid:id="@+id/thumbImage"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true" 
        /><CheckBoxandroid:id="@+id/itemCheckBox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentTop="true" /></RelativeLayout>

Post a Comment for "Does Whatsapp Uses The Native Gallery While Sharing Images"