【发布时间】:2014-01-08 22:02:09
【问题描述】:
我正在尝试找出一种方法来保存我的 InputStream 中的数据并将其用于另一个活动。到目前为止,我已尝试按以下方式使用 sharedPreferences - 但我收到一条错误消息:
"The method putString(String, String) in the type SharedPreferences.Editor is not applicable for the arguments (String, InputStream)"
上线:
editor.putString("fileName", attachment);
如何避免这种情况?
来源:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get the attachment's filename
Intent theIntent = getIntent();
String attachmentFileName = "No file name found";
if (theIntent != null && theIntent.getData() != null) {
Cursor c = getContentResolver().query(theIntent.getData(), null,
null, null, null);
c.moveToFirst();
final int fileNameColumnId = c
.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (fileNameColumnId >= 0)
attachmentFileName = c.getString(fileNameColumnId);
try {
InputStream attachment = getContentResolver().openInputStream(
getIntent().getData());
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("fileName", attachment);
editor.commit();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
标签: java android attachment email-attachments fileoutputstream