【发布时间】:2014-08-15 03:11:04
【问题描述】:
我正在寻找如何将图像数据存储到我在 Android Wear 上的应用中。
我想做的是:
拍照并发送到我的手表。 (通过 DataMap)
我的手表显示照片。
当我在 Android Wear 上的应用重新启动时,应用会显示之前拍摄的照片。
目前,重启应用后照片会被清除。我想存储照片。
有什么方法可以将照片保存到手表中。
谢谢。
[更新1]
我尝试使用Environment.getExternalStorageDirectory() 保存图像
但返回“不存在”。
String imagePath = Environment.getExternalStorageDirectory()+"/test.jpg";
try {
FileOutputStream out = openFileOutput(imagePath, Context.MODE_WORLD_READABLE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
File file = new File(bitmapPath);
boolean isExists = file.exists();
if (isExists) {
LOGD(TAG, "EXISTS");
} else {
LOGD(TAG, "NOT EXISTS");
}
[更新2]
我在下面发现了一个错误..
java.lang.IllegalArgumentException: File /storage/emulated/0/test.jpg contains a path separator
[更新3]
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(path));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
java.io.FileNotFoundException: /image: open failed: EROFS (Read-only file system)
[更新4]
我说的。但不会改变。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
[已解决更新5]
我发现路径“imagePath”是正确的。 (对不起,我没注意到)
String imagePath = Environment.getExternalStorageDirectory() + "/test.jpg";
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(imagePath));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
【问题讨论】:
-
您确定位图已清除?对我来说,使用此代码重新启动后图像仍然可用:github.com/heinrisch/talkclient/blob/master/src/main/java/se/…
-
@Heinrisch 真的!?谢谢!我现在检查一下。
-
@Heinrisch,当您使用“Wearable.DataApi.putDataItem”保存对象时?此对象存储多长时间并可用于“Wearable.DataApi.getDataItems”?当您关闭手表或与移动设备的连接丢失时,此对象是否仍然存在?
-
我真的不知道。我从未经历过物品丢失。尽管关闭和连接中断,它仍然有效。