有意图传递文件,我该如何检索它 [英] Passing File with intent, how do i retrieve it

查看:114
本文介绍了有意图传递文件,我该如何检索它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要经过的。 pictureFile 是一个文件

Here is what I am passing. pictureFile is a File

Intent intent = new Intent (context, ShowPicActivity.class);
intent.putExtra("picture", pictureFile);

在接下来的活动中我会使用其中一个吸气剂来获取它吗?

In the next activity which one of the getters do I use to get it?

Intent intent = getIntent(); .....?

推荐答案

尝试以下方法:

YourPictureClass picture = (YourPictureClass)getIntent.getExtras().get("picture");

在你的<中调用 getExtras() code> Intent 你得到一个 Bundle 的实例。

正常获取()在类 Bundle 中你可以读取每个对象你传递给调用意图。你唯一要做的就是将它解析回你的对象是一个实例。

By calling getExtras() in your Intent you get an instance of Bundle.
With the normal get() in class Bundle you can read every Object you pass to the calling Intent. The only thing you have to do is to parse it back to the class your object is an instance of.

这篇关于有意图传递文件,我该如何检索它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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