如何将 Uri 图像从一个活动转移到另一个活动? [英] How to transfer a Uri image from one activity to another?
本文介绍了如何将 Uri 图像从一个活动转移到另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我需要将 Uri 图像从我的第一个 Activity 传输到另一个.我知道如何通过意图发送位图.我是一个大程序员,所以我不知道怎么做会更好:有意图地传输 Uri 或将 Uri 更改为位图然后发送?
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");
}
使用这些功能:Uri 到字符串:
Use those func: Uri to String:
Uri uri;
String stringUri;
stringUri = uri.toString();
字符串到 Uri:
Uri uri;
String stringUri;
uri = Uri.parse(stringUri);
这篇关于如何将 Uri 图像从一个活动转移到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文