Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Wear:如何将图像数据存储到手表中_Android_Wear Os - Fatal编程技术网

Android Wear:如何将图像数据存储到手表中

Android Wear:如何将图像数据存储到手表中,android,wear-os,Android,Wear Os,我正在寻找如何将图像数据存储到我的Android Wear应用程序中 我想做的是: 拍一张照片并把它送到我的手表上。(通过数据地图) 我的手表显示这张照片 当我的Android Wear应用程序重新启动时,该应用程序会显示之前拍摄的照片 目前,重新启动应用程序后,照片将被清除。我想把照片存起来 有没有办法把照片保存到手表里 谢谢 [更新1] 我试图使用Environment.getExternalStorageDirectory()保存图像 但返回“notexists” String image

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

我想做的是:

  • 拍一张照片并把它送到我的手表上。(通过数据地图)

  • 我的手表显示这张照片

  • 当我的Android Wear应用程序重新启动时,该应用程序会显示之前拍摄的照片

  • 目前,重新启动应用程序后,照片将被清除。我想把照片存起来

    有没有办法把照片保存到手表里

    谢谢

    [更新1]


    我试图使用
    Environment.getExternalStorageDirectory()保存图像

    但返回“notexists”

    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" />
    

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

    尝试类似于
    openFileOutput(“test.jpg”,Context.MODE\u WORLD\u READABLE)的方法(不推荐使用仅供参考的世界可读模式)

    然后使用
    openFileInput(“test.jpg”)
    将其取回


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

    非常感谢。正如您所说,Environment.getExternalStorage()可用于存储图像。伟大的回答!那么正确的答案是什么呢?Environment.getExternalStorage()是否可用?Environment.getExternalStorage()可用。我用我的应用程序测试过,你可以看一下:你确定位图被清除了吗?对我来说,重新启动后图像仍然可用,代码为:@Heinrisch Really!?谢谢我现在检查它。@Heinrisch,当您使用“Wearable.DataApi.putDataItem”保存对象时?此对象存储多长时间并可用于“Wearable.DataApi.getDataItems”?当你关闭手表或者与移动设备的连接丢失时,这个物体是否会持续存在?我真的不知道。我从未经历过物品丢失的情况。它在关闭和连接中断的情况下仍然有效。
    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();
    }