如何将Uri图像从一个活动转移到另一个活动? [英] How to transfer a Uri image from one activity to another?

查看:133
本文介绍了如何将Uri图像从一个活动转移到另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要将Uri图像从第一个Activity转移到另一个Activity。我知道如何通过意图发送位图。我是一个比较粗壮的程序员,所以我不知道最好做什么:转移Uri有意图或将Uri更改为Bitmap然后发送?

In my app I need to transfer a Uri image from my first Activity to another. I know how to send a Bitmap through an intent. I'm a bigginer programmer so I don't know what would be better to do: transfer the Uri with an intent or change the Uri to a Bitmap then send that?

推荐答案

与putExtra一起使用以发送Uri路径:

use with putExtra to send the Uri Path:

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent .setClass(ThisActivity.this,  NewActivity.class);
            intent .putExtra("KEY", Uri);
            startActivity(intent );

在newActivity OnCreate方法中:

In the newActivity OnCreate method:

   Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("KEY")) {
        Uri= extras.getString("KEY");
    }

使用那些func:
Uri to String:

Use those func: Uri to String:

Uri uri;
String stringUri;
stringUri = uri.toString();

字符串到Uri:

Uri uri;
String stringUri;
uri = Uri.parse(stringUri);

这篇关于如何将Uri图像从一个活动转移到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆