gpt4 book ai didi

Android - 媒体扫描仪不适用于 api 28-29

转载 作者:行者123 更新时间:2023-12-03 14:43:09 26 4
gpt4 key购买 nike

我正在使用 MediaScanner 扫描文件.但是 API 28 和 29 不起作用。

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, file));

我用了 Broadcast ,但它的工作方式不同。因为它已“弃用”。
java public static class FilesScanner extends ContextWrapper implements MediaScannerConnection.MediaScannerConnectionClient{

private MediaScannerConnection connection = null;
private String SCAN_FILE_PATH = "";
private String SCAN_FILE_MIME_TYPE = "*/*";

public static FilesScanner with(Context context, String SCAN_FILE_PATH){ return new FilesScanner(context, SCAN_FILE_PATH, "*/*"); }
public static FilesScanner with(Context context, String SCAN_FILE_PATH, String SCAN_FILE_MIME_TYPE){ return new FilesScanner(context, SCAN_FILE_PATH, SCAN_FILE_MIME_TYPE); }
private FilesScanner(Context context, String SCAN_FILE_PATH, String SCAN_FILE_MIME_TYPE){
super(context);
this.SCAN_FILE_PATH = SCAN_FILE_PATH;
if (SCAN_FILE_PATH == null){
this.SCAN_FILE_PATH = FilePaths.ROOT_DIR;
}
this.SCAN_FILE_MIME_TYPE = SCAN_FILE_MIME_TYPE;
if (SCAN_FILE_MIME_TYPE == null){
this.SCAN_FILE_MIME_TYPE = "*/*";
}
connection = new MediaScannerConnection(this, this);
connection.connect();
}

@Override
public void onMediaScannerConnected() {
MyLog.d("onMediaScannerConnected");
connection.scanFile(SCAN_FILE_PATH, SCAN_FILE_MIME_TYPE);
}

@Override
public void onScanCompleted(String path, Uri uri) {
MyLog.d("onScanCompleted" + " URI : " + uri.getPath());
connection.disconnect();
}
}
FilesScanner.with(this, path, "image/*");

最佳答案

您是否将其添加到 list 文件中?

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${app_package_name}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

关于Android - 媒体扫描仪不适用于 api 28-29,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57520273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com