Phonegap Android:保存的图片显示为缓存组

时间:2013-02-22 03:44:45

标签: android cordova camera phonegap-plugins android-gallery

我使用Phonegap和image-resizer插件使用以下代码将图像保存到Android设备中:

try {
  // Obligatory Parameters, throw JSONException if not found
  String filename = params.getString("filename");
  filename = (filename.contains(".")) ? filename : filename + "."+ format;
  String directory = params.getString("directory");
  directory = directory.startsWith("/") ? directory : "/"+ directory;
  int quality = params.getInt("quality");
  OutputStream outStream;
  //store the file locally using the external storage directory
  File file = new File(Environment.getExternalStorageDirectory()
    .toString() + directory, filename);
  try {
    outStream = new FileOutputStream(file);
    if (format.equals(FORMAT_PNG)) {
      bmp.compress(Bitmap.CompressFormat.PNG, quality, outStream);
    } else {
      bmp.compress(Bitmap.CompressFormat.JPEG, quality, outStream);
    }
    outStream.flush();
    outStream.close();
    JSONObject res = new JSONObject();
    res.put("url", "file://" + file.getAbsolutePath());
    result = new PluginResult(Status.OK, res);
    scanPhoto(imageData.substring(8));
  } catch (IOException e) {
      result = new PluginResult(Status.ERROR, e.getMessage());
  }
  } catch (JSONException e) {
    result = new PluginResult(Status.JSON_EXCEPTION, e.getMessage());
  }
}

然后,在图库中可以使用此功能:

private void scanPhoto(String imageFileName) {
  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
  File f = new File(imageFileName);
  Uri contentUri = Uri.fromFile(f);
  mediaScanIntent.setData(contentUri);
  this.cordova.getActivity().sendBroadcast(mediaScanIntent);
}

更新:然而,当我去画廊时,图像位于一个名为缓存的组中,因此我有2组摄像头和缓存。如何将其更改为应用程序的名称? - 在使用我的应用名称

的文件夹中存储目录后立即获得应用名称

0 个答案:

没有答案