将图像从其他应用分享到我的应用

Sharing image from other apps unto my app

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

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

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


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

感谢您的帮助!

你可以像这样在activity中获取图片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
                }

            }
        }


    }

您可以检查 link 其他 mime 类型 Handle the Incoming Content