Android Wear:如何将图像数据存储到手表 [英] Android Wear: how to store image data into watch

查看:471
本文介绍了Android Wear:如何将图像数据存储到手表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找如何将图像数据存储到我的Andr​​oid Wear应用。

我想要做的是什么如下:


  1. 拍摄照片并将其发送给我的手表。 (通过数据映射)


  2. 我的手表显示的照片。


  3. 在我的Andr​​oid Wear重新启动应用程序,该应用程序会显示之前拍摄的照片。


目前,该照片被清零重新启动应用程序后。我想存储的照片。

有什么方法来保存照片到手表。

感谢。

[UPDATE1]

我尝试用 Environment.getExternalStorageDirectory()

保存图像

但是,NOT EXISTS被返回。

 字符串的ImagePath = Environment.getExternalStorageDirectory()+/ test.jpg放在尝试{
  FileOutputStream中出= openFileOutput(的ImagePath,Context.MODE_WORLD_READABLE);
  bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,出);
  out.close();
}赶上(例外五){
  e.printStackTrace();
}档案文件=新的文件(bitmapPath);
布尔isExists = file.exists();
如果(isExists){
  LOGD(TAG,存在);
}其他{
  LOGD(TAG,NOT EXISTS);
}

[UPDATE2]

我发现以下..

错误

  java.lang.IllegalArgumentException异常:文件/storage/emulated/0/test.jpg包含路径分隔符

[UPDATE3]

  {尝试
  的BufferedOutputStream出=新的BufferedOutputStream(新的FileOutputStream(路径));
  bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,出);
  out.close();
}赶上(例外五){
  e.printStackTrace();
}java.io.FileNotFoundException:/图片:打开失败:EROFS(只读文件系统)

[UPDATE4]

我把它。但不能更改。

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>

[UPDATE5解决]

我发现道路的ImagePath是正确的。 (对不起,我没有注意到吧)

 字符串的ImagePath = Environment.getExternalStorageDirectory()+/test.jpg尝试{
    的BufferedOutputStream出=新的BufferedOutputStream(新的FileOutputStream(的ImagePath));
    bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,出);
    out.close();
}赶上(例外五){
    e.printStackTrace();
}


解决方案

我相信你有问题,因为 openFileInput()是内部存储,而不是外部存储。事实上,没有理由使用 Environment.getExternalStorage()。我不相信的手表有外部存储无妨。

试着像 openFileOutput(test.jpg放在Context.MODE_WORLD_READABLE); (FYI MODE_WORLD_READABLE是德precated)

然后使用 openFileInput(test.jpg放在)来把它找回来。

您收到错误的原因是openFileOutput()不能有子目录。

I'm looking for how to store image data into my app on Android Wear.

What I want to do are followings:

  1. Take a photo and send it to my watch. (via DataMap)

  2. My watch displays the photo.

  3. When my app on Android Wear restarts, the app displays the photo taken before.

For now, the photo is cleared after restart the app. I want to store the photo.

Are there any ways to save the photo into the watch.

Thanks.

[UPDATE1]

I tried to save an image by using Environment.getExternalStorageDirectory()

But "NOT EXISTS" is returned.

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");
}

[UPDATE2]

I found an error below..

java.lang.IllegalArgumentException: File /storage/emulated/0/test.jpg contains a path separator

[UPDATE3]

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)

[UPDATE4]

I put it. But not change.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

[UPDATE5 SOLVED]

I found that the path "imagePath" was correct. (Sorry. I didn't notice it)

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();
}

解决方案

I believe you are having problems because openFileInput() is for internal storage, not external storage. In fact there is no reason for using Environment.getExternalStorage(). I don't believe the watches have external storage anyway.

Try something like openFileOutput("test.jpg", Context.MODE_WORLD_READABLE); (fyi MODE_WORLD_READABLE is deprecated).

Then use openFileInput("test.jpg") to get it back.

The reason you are getting an error is openFileOutput() cannot have subdirectories.

这篇关于Android Wear:如何将图像数据存储到手表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆