I have a big issue with ShareActionProvider
. My application is like a gallery application using ViewPager
, that keeps track of favorite image items, and gives possibility to share them through ShareActionProvider
.
Everything works fine except that whichever image I scroll to is saved in the directory I use to get Uri.
Here is my code
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.menu_fragement_gallery, menu);
mMenu = menu;
favoriteItem = mMenu.findItem(R.id.idItemFavoris);
MenuItem item = (MenuItem) mMenu.findItem(R.id.idItemShashare);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
initShareIntent();
}
private void initShareIntent() {
if (mShareActionProvider != null) {
Uri bmpUri = getLocalBitmapUri(mCurrentImage);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
shareIntent.setType("image/*");
mShareActionProvider.setShareIntent(shareIntent);
}
}
public Uri getLocalBitmapUri(ImageView imageView) {
if(imageView != null){
Drawable mDrawable = imageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(),
mBitmap, "Image Description", null);
Uri uri = Uri.parse(path);
return uri;
}
return null;
}
I need to call
getActivity().invalidateOptionsMenu();
each time I instatiate the view in the ViewPager
class GalleryViewPagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return listeOfPhotos.size();
}
@Override
public View instantiateItem(ViewGroup container, int position) {
mPhoto = listeOfPhotos.get(position);
ImageLoader.getInstance()
.displayImage(mPhoto.getUrl(), mCurrentImage, FragmentGallery.options, null, null);
container.addView(mCurrentImage, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
//Change the Favorite Icon and Invalidate Menu
initIconFavorite();
return mCurrentView;
}
}
I would be glad if you guys help me with this problem.
Thank you