我正在寻找如何将图像数据存储到我的Android Wear应用中。
我想要做的事情如下:
1. 拍照并将其发送到手表上(通过DataMap)。 2. 我的手表显示照片。 3. 当我在Android Wear上的应用重新启动时,应用会显示之前拍摄的照片。
目前,重启应用后照片会被清除。我想要存储照片。
有没有任何方法可以将照片保存到手表中?
谢谢。
[更新1]
我尝试使用Environment.getExternalStorageDirectory()保存图像,但返回“NOT EXISTS”。
[更新2]
我发现以下错误...
[更新3]
[更新4]
我放置了它。但并没有改变。
我想要做的事情如下:
1. 拍照并将其发送到手表上(通过DataMap)。 2. 我的手表显示照片。 3. 当我在Android Wear上的应用重新启动时,应用会显示之前拍摄的照片。
目前,重启应用后照片会被清除。我想要存储照片。
有没有任何方法可以将照片保存到手表中?
谢谢。
[更新1]
我尝试使用Environment.getExternalStorageDirectory()保存图像,但返回“NOT EXISTS”。
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 已解决]
我发现"path"路径是正确的。(抱歉,我没有注意到它)
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();
}