Nativescript从库中删除图像

Nativescript从库中删除图像,nativescript,Nativescript,我有一个NS 4.1和TS应用程序。在其中,我允许用户使用选择图像 如果用户选择这样做,我想从设备中删除图像。我正在使用以下代码: //文件是文件位置的列表:例如/storage/simulated/0/DCIM/Camera/IMG_1529637637242.jpg 从“tns核心模块/文件系统”导入*作为fs; files.forEach(f=>{ 让file:fs.file=fs.file.fromPath(f); 如果(文件) file.remove(); });您可以为给定路径手动

我有一个NS 4.1和TS应用程序。在其中,我允许用户使用选择图像

如果用户选择这样做,我想从设备中删除图像。我正在使用以下代码:

//文件是文件位置的列表:例如/storage/simulated/0/DCIM/Camera/IMG_1529637637242.jpg
从“tns核心模块/文件系统”导入*作为fs;
files.forEach(f=>{
让file:fs.file=fs.file.fromPath(f);
如果(文件)
file.remove();

});您可以为给定路径手动触发媒体扫描仪。这将反映这些变化。 这是android的代码

    android.content.Intent mediaScanIntent = new android.content.Intent(android.content.Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    android.net.Uri contentUri = android.net.Uri.fromFile(imageFile);
    mediaScanIntent.setData(contentUri);
    application.android.context.sendBroadcast(mediaScanIntent);
或者你也可以在下面做

    android.media.MediaScannerConnection.scanFile(application.android.context, [picturePath], null, callback);

可能是库中的路径与DCIM不同,所以您也必须将其删除