【问题标题】:how to create a Share Intent for an ImageView?如何为 ImageView 创建共享意图?
【发布时间】:2011-11-24 08:21:48
【问题描述】:

我正在创建一个照片应用程序,用户可以在其中从图库中选择图像,并显示在应用程序中心的图像视图中。我将如何为 ImageView 创建共享意图?

更新 共享意图有效,但是无法共享图像,因为我无法将其保存到我选择的路径。下面是我的代码。有什么帮助吗?

public void taptoshare(View v)
    {  
        View content = findViewById(R.id.myimage);
        content.setDrawingCacheEnabled(true);
            Bitmap bitmap = content.getDrawingCache();
            File file = new File("/DCIM/Camera/image.jpg");
            try 
            {
                file.createNewFile();
                FileOutputStream ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.JPEG, 100, ostream);
                ostream.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }


        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        Uri phototUri = Uri.parse("/DCIM/Camera/image.jpg");
        shareIntent.setData(phototUri);
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
        startActivity(Intent.createChooser(shareIntent, "Share Via"));

}  

}

【问题讨论】:

  • 你想分享图片还是从本地图库中挑选图片?
  • 我想分享在 ImageView 中显示的图像(用户从图库中选择的照片)

标签: java android android-intent imageview share


【解决方案1】:

试试这个

Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse(path);
shareIntent.setData(photootUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, photootUri);
getContext().startActivity(Intent.createChooser(shareIntent, "Use this for sharing"));

【讨论】:

  • 分享意图效果很好!但是,如何将图像视图中的图像保存到磁盘?弹出菜单并分享所有内容,但由于找不到指定路径而失败。
  • 您需要从相机应用程序中保存图像。然后,您可以在共享意图中传递该文件路径 uri。 technotalkative.com/android-pick-image-from-native-gallery
【解决方案2】:

请参阅以下链接。这对你很有帮助。我认为它满足您的要求。

http://www.technotalkative.com/android-pick-image-from-native-gallery/

【讨论】:

  • 这实际上帮助了我解决内存分配问题.. 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 2021-02-15
相关资源
最近更新 更多