将图像从其他应用程序共享到我的应用程序

Sharing image from other apps unto my app

提问人:Erik Andersson 提问时间:5/25/2015 更新时间:5/25/2015 访问量:111

问:

当用户将图像从另一个应用共享到我的应用时,我希望将其作为图像接收并处理它。

我已经设置了这样的过滤器:

Like so

现在我不明白的是,如何在我的应用程序中实际接收意图,也不知道如何从中提取/处理图像。


我尝试在谷歌上搜索这个问题,但似乎没有人给出关于设置过滤器后如何处理/接收意图的具体答案。

我很感激你的帮助!

Java Android-intent 共享

评论


答:

2赞 Chandrakanth 5/25/2015 #1

可以像这样在活动中获取图像 uri

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if (type.startsWith("image/")) {
                Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (imageUri != null) {
                    // Do whatever you want here
                }

            }
        }


    }

您可以查看其他 mime 类型的链接 处理传入内容