cocosCreator 2.0.4 在ios和android保存图片到相册问题

安卓保存图片到本地根据官方文档已经保存成功,但是却找不到这张图片

这个保存到应用的读写目录了,要找到的话要root才行

那如果正常用户使用呢,路径是否要改,还是需要怎么去做

应用是可以直接访问的,用户如果没有root就没办法访问,应用卸载后,这个目录也会删除。你可以原生写个保存方法,保存到外部存储,不知道你的需求是什么

现在的需求就是保存图片到相册,因为原生的方法不会

据我所知,cocos没有提供外部路径的获取方法,你至少要写一个获取外部路径的方法,

拷贝到外部存储,然后通知相册更新
public static void refreshPhoto( String pngPath, String pngName) {
Log.i(“RefreshPhoto”,pngPath);
File file = new File(pngPath);
String tempFile = Environment.getExternalStorageDirectory().getPath() + “/” + pngName;
boolean copyres = copyFile(file, tempFile);
Log.i(TAG, “copyres: " + copyres + " tempFile:” + tempFile);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(tempFile)));
getContext().sendBroadcast(intent);
Log.i(“RefreshPhoto”,“over”);
}

/**
 * 根据文件路径拷贝文件
 * @param src 源文件
 * @param destPath目标文件路径
 * @return boolean 成功true、失败false
 */
public static boolean copyFile(File src, String destPath ) {
    boolean result = false;
    if ((src == null) || (destPath== null)) {
        return result;
    }
    File dest= new File(destPath);
    if (dest!= null && dest.exists()) {
        dest.delete(); // delete file
    }
    try {
        dest.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileChannel srcChannel = null;
    FileChannel dstChannel = null;

    try {
        srcChannel = new FileInputStream(src).getChannel();
        dstChannel = new FileOutputStream(dest).getChannel();
        srcChannel.transferTo(0, srcChannel.size(), dstChannel);
        result = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return result;
    } catch (IOException e) {
        e.printStackTrace();
        return result;
    }
    try {
        srcChannel.close();
        dstChannel.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}