【问题标题】:Sharing image from other apps unto my app将其他应用程序中的图像共享到我的应用程序
【发布时间】:2015-05-25 09:03:23
【问题描述】:

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

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

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


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

感谢您的帮助!

【问题讨论】:

    标签: java android android-intent share


    【解决方案1】:

    你可以像这样在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
                    }
    
                }
            }
    
    
        }
    

    您可以查看其他 mime 类型的链接Handle the Incoming Content

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 2022-11-15
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      相关资源
      最近更新 更多