安卓磨损 : how to store image data into watch

标签 android wear-os

我正在寻找如何将图像数据存储到我的 Android Wear 应用中。

我想做的是:

  1. 拍照并将其发送到我的 watch 。 (通过 DataMap)

  2. 我的 watch 显示照片。

  3. 当我在 Android Wear 上的应用重新启动时,该应用会显示之前拍摄的照片。

目前,照片在重启应用程序后被清除。我想存储照片。

有什么方法可以把照片保存到 watch 里。

谢谢。

[更新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" />

[UPDATE5 已解决]

我发现路径“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();
}

最佳答案

我相信您遇到了问题,因为 openFileInput() 用于内部存储,而不是外部存储。事实上,没有理由使用 Environment.getExternalStorage()。我不相信 watch 有外部存储。

尝试类似openFileOutput("test.jpg", Context.MODE_WORLD_READABLE);(仅供引用,MODE_WORLD_READABLE 已弃用)。

然后使用 openFileInput("test.jpg") 将其取回。

出现错误的原因是 openFileOutput() 不能有子目录。

关于安卓磨损 : how to store image data into watch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25320747/

相关文章:

Android Studio - 全局设置构建目录(每台机器)

android - 没有环境模式就一直打开?或者进入环境时不变暗?

java - Android Wear 检测到 "Mute"

android - HTC Sense 复制/粘贴 API

android - 如果我的应用程序在我的 Android Studio 模拟器上运行缓慢,它会在设备上运行缓慢吗?

Android签名保护并导出="false"

android - 以编程方式在android中打开.msg文件(Outlook项目文件)

android - 我们需要用什么来代替 Android 中的 wear api?

android - onDataChanged 监听器未检测到数据传输(Data Api)

android - 在 Android studio 中旋转 Canvas 上的位图