cordova 错误:找不到符号:方法createUriForFile(上下文,文件)

qlfbtfca  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(193)

我试过Cordova Android clicking input problemNoodleOfDeath's solution,但我面临着一个问题:"cannot find symbol"createTempFilecreateUriForFile方法。据我所知,我应该导入这些方法,但谷歌没有显示任何例子。或者它应该是一些库,其中有这些方法,或只有@ NoodleOfDeath需要代码。我想直接问这个问题,但没有声誉作出评论,所以我必须创建这个头。而且我是java新手,所以如果我的问题听起来很蠢我很抱歉。

icomxhvb

icomxhvb1#

我已经解决了这个问题。不确定这是不是最好的方法,但它可以在我的设备上运行android 11和cordova 9.0。我已经在NoodleOfDeath的解决方案中修改了onShowFileChooser方法体内的try-catch块。

try {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "img_"+timeStamp+"_";
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        File tempFile = File.createTempFile(imageFileName,".jpg", storageDir);
        Log.d(LOG_TAG, "Temporary photo capture file: " + tempFile);
        tempUri = Uri.fromFile(tempFile);                              
        Log.d(LOG_TAG, "Temporary photo capture URI: " + tempUri);
        captureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempUri);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Unable to create temporary file for photo capture", e);
        captureIntent = null;
    }

相关问题