在 Titanium Mobile 中更改 applicationDataDirectory 文件的权限
我正在尝试使用 Titanium Mobile 通过手机的电子邮件客户端以附件形式发送文件。我遇到了一个问题:附件已发送,但接收时为 0 字节文件。
问题是在 data/data/package/app_appdata
中创建的文件是 -rw------
从 Android SDK 来看,这是设计使然。应用程序的“私有存储”只能由该文件夹的所有者(正在运行的应用程序)读取。 我认为 Android 电子邮件客户端可以看到该文件,但无法读取它。
完整的 Android SDK 提到了 MODE_WORLD_WRITABLE,它允许您继续使用 applicationDataDirectory 并授予所有应用程序读取/写入该文件的权限。 Titanium Mobile 中是否存在同等功能?
另一个解决方案是创建一个临时文件,不幸的是它使用 Titanium 自己的命名方案(tiXXXXX.txt),或者我可以写入“外部存储”,因为它是公共的(但是,它可能并不总是可用。)
这是我用来获取当前文件的调用,可以在我的应用程序中很好地读取它,但是当我使用 emailDialog
的 addAttachment
调用时,它只是发送一个0字节文件给我。
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "generated_filename.txt")
I'm trying to send a file, as an attachment, via the phone's e-mail client using Titanium Mobile. I've run into a snag where the attachment is sent, but is received as a 0-byte file.
The problem is that the file created in data/data/package/app_appdata
is -rw------
From glancing at the Android SDK, this is by design. The app's "private storage" is readable only by the owner of that folder, the running application.
I presume that the Android e-mail client can see that file, but cannot read it.
The full Android SDK mentions a MODE_WORLD_WRITABLE that allows you to keep using the applicationDataDirectory and give all apps permission to read/write that file. Does an equivalent exist in Titanium Mobile?
The other solution is to create a temp file, which unfortunately uses Titanium's own naming scheme (tiXXXXX.txt), or I could write to the "external storage" since it is public (which may not always be available, however.)
This is the call I'm using to get the current file, it can be read within my app just fine, but when I use the addAttachment
call of an emailDialog
it simply sends a 0 byte file to me.
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "generated_filename.txt")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
tempDirectory
来代替。当然,我假设文件通过电子邮件发送后,您不需要保留它,因为applicationDataDirectory
已完全备份并且通常用于存储应用程序保留的数据。http://developer.appcelerator.com/apidoc/mobile /latest/Titanium.Filesystem.tempDirectory-property.html
Have you tried using
tempDirectory
instead. I'm of course assuming once the file is emailed you don't need to keep it as theapplicationDataDirectory
is fully backed up and usually used to store data the app retains.http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Filesystem.tempDirectory-property.html