我正在使用 FileSystemStorage 来存储用户可以共享的文件(如果他们愿意)。存储效果很好,但是当用户选择共享(仅限 Android 设备)文件时,附件的前缀为 IMG_DATE_TIME_,然后是文件名。这种情况仅在第二次共享文件时发生。第一次尝试很好。到目前为止,Gmail、Hotmail 和 WhatsApp 也是如此。我已经用 txt、csv 和 xlsx 文件对此进行了测试,它们都执行相同的操作。我做错了什么吗?任何帮助将不胜感激。下面的测试用例:-
public void FSStoragePage(Form mainForm){
Form form = new Form("File System Storage", new BorderLayout());
form.getToolbar().setBackCommand("", e -> mainForm.showBack());
Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
centercnt.setScrollableY(true);
Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
TextField tf_fileName = new TextField("", "File name", 3, TextArea.ANY);
TextField tf_txtBody = new TextField("Text Body", "Enter text", 3, TextArea.ANY);
Button b_saveTxt = new Button("Save");
Button b_shareTxt = new Button("Share");
String s_emailSubject = "";
Message m = new Message("");
String s_emailAddr = "";
FileSystemStorage fs = FileSystemStorage.getInstance();
String testDir = fs.getAppHomePath() + "testDirectory/";
b_saveTxt.addActionListener(actionEvent -> {
boolean bool_exists = fs.exists(testDir);
if(!bool_exists){
String testDirNew = fs.getAppHomePath() + "testDirectory/";
fs.mkdir(testDirNew);
}
try (OutputStream os = fs.openOutputStream(testDir + tf_fileName.getText().trim()+".txt")) {
String fileContent = tf_txtBody.getText().trim();
os.write(fileContent.getBytes("UTF-8"));
} catch (IOException err) {
Log.e(err);
}
});
b_shareTxt.addActionListener(actionEvent -> {
String filePath = testDir+tf_fileName.getText().trim()+".txt";
if (fs.exists(filePath)) {
m.setAttachment(filePath);
m.setAttachmentMimeType("text/plain");
Display.getInstance().sendMessage(new String[]{s_emailAddr}, s_emailSubject, m);
} else {
Dialog.show("Error", "The file does not exist.", "OK", null);
}
});
centercnt.add(tf_fileName);
centercnt.add(tf_txtBody);
centercnt.add(b_saveTxt);
centercnt.add(b_shareTxt);
form.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);
form.show();
}
这已在此处讨论过。
解决方案是在您的
init(Object)
方法中定义它,这将禁用该行为:
Display.getInstance().setProperty("DeleteCachedFileAfterShare", "true");