我正在开发一个Android应用程序,它是一个图像库,其中的图像从互联网下载,以显示在smathphone的屏幕上.图像一次显示一个,应用程序有一个按钮来共享显示的图像.
根据我在一些StackOverflow帖子中发现的指示,该帖子表明共享图像的正确方法是使用ContentProvider我实现了以下代码,用于共享某些应用程序的图像(例如Twitter,Gmail ...)但对其他人不起作用(Facebook,Yahoo,MMS ......).
然后我展示了使用的代码,希望你能帮助我获得正确的实现,以在所有应用程序中共享图像.
最初我抓住按钮按下来分享:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_share) {
// I get the image being displayed on the screen
View root = getView();
ImageView imageView = (ImageView) root.findViewById(R.id.image);
Drawable imageToShareDrawable = imageView.getDrawable();
if (imageToShareDrawable instanceof BitmapDrawable) {
// I convert the image to Bitmap
Bitmap imageToShare = ((BitmapDrawable) imageToShareDrawable).getBitmap();
// Name of de image extracted from a bean property
String fileName = quote.getImage();
// I keep the image in the folder "files" …Run Code Online (Sandbox Code Playgroud)