写入 android 本地磨损

Writing to android wear locally

我正在尝试将连续的数据流写入磨损设备上的 android 本地磨损。我有一个名为 DataSaver 的 class,它在 phone 端工作得很好,但相同的代码在可穿戴设备上不起作用。我有 android 在 Wear 和移动设备上写入和读取的权限。

在 DataSaver 的构造函数中,我有以下内容:

if (!isExternalStorageWritable()) Log.e(TAG, "External storage is not writable"); //This line does not show anything on the log. So, esExternalStorageWritable returns false.
File rootDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);//Environment.getExternalStorageDirectory();
if (!rootDir.canWrite())
{
  Log.d(TAG, "cannot write in the root: "+rootDir.toString()+", space: "+rootDir.getUsableSpace()+", can read: "+rootDir.canRead()+", list: "+rootDir.list());
}

函数isExternalStorageWritable()实现如下:

/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable()
{
  String state = Environment.getExternalStorageState();
  if (Environment.MEDIA_MOUNTED.equals(state))
  {
    return true;
  }
  return false;
}

这总是在我检查 rootDir 是否可以写入的 if 语句中。 rootDir.canRead 也returns false。设备上的免费 space 返回为 2.2GB。

后面几行中的 mkdirs 失败,因为它无法写入 root。有什么想法,建议吗?我将不胜感激。

问题是我必须在手表的设置中手动授予权限才能正常工作。基本上转到:设置 -> 权限 -> 你的应用程序,并检查存储是否被禁用(在我的情况下)。单击一次以切换值。

记得对清单有写入权限。