繁体   English   中英

如何为ImageView创建共享意图?

[英]how to create a Share Intent for an ImageView?

我正在创建一个照片应用程序,用户从库中选择和图像,它显示在应用程序中心的图像视图中。 我将如何为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"));

}  

}

尝试这个

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"));

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM