AndroidQ:通过内容解析器更改外部文件的lastModified日期”
创始人
2024-10-09 14:35:05
0

针对Android Q的新特性,应用程序的访问权限得到了更加严格的限制。因此,要在Android Q上更改外部文件的最后修改日期,需要使用新的方式。下面是通过内容解析器更改外部文件的最后修改日期的示例代码:

Uri uri = MediaStore.Files.getContentUri("external");
String selection = MediaStore.Files.FileColumns.DATA + "=?";
String[] selectionArgs = new String[]{filePath};
ContentResolver resolver = getContentResolver();
String[] projection = {MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATE_MODIFIED};
Cursor cursor = resolver.query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
    long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Files.FileColumns._ID));
    ContentValues values = new ContentValues();
    values.put(MediaStore.Files.FileColumns.DATE_MODIFIED, System.currentTimeMillis());
    String updateSelection = MediaStore.Files.FileColumns._ID + "=?";
    resolver.update(uri, values, updateSelection, new String[]{String.valueOf(id)});
}
if (cursor != null) {
    cursor.close();
}

首先,我们通过MediaStore.Files.getContentUri("external")获取文件的Uri。然后我们使用MediaStore提供的投影,只查询要更改的文件,并将其最后修改日期设置为当前时间。最后,使用ContentResolver更新文件的Uri。

注意,在Android Q中,必须有WRITE_EXTERNAL_STORAGE权限并使用MediaStore才可以更改外部文件的最后修改日期。

相关内容

热门资讯

透视最新!德普之星透视辅助,w... 透视最新!德普之星透视辅助,wepoker有没有挂,高科技教程(真是存在有挂)是一款可以让一直输的玩...
透视透视!aapoker辅助功... 透视透视!aapoker辅助功能,wpk透视辅助,让我来分享经验(有挂教程)1、玩家可以在wpk透视...
透视辅助!wepoker透视版... 1、透视辅助!wepoker透视版下载,wepoker辅助是真的假的,透明挂教程(起初真的是有挂);...
透视游戏!wpk脚本下载,wp... 透视游戏!wpk脚本下载,wpk脚本是什么,科普攻略(有挂透明)透视游戏!wpk脚本下载,wpk脚本...
透视工具!aapoker辅助插... 此外,数据分析德州(aapoker辅助插件工具下载)辅助神器app还具备辅助透视行为开挂功能,通过对...
透视最新!wepoker透视脚... 透视最新!wepoker透视脚本下载,红龙poker有辅助吗,程序员教你(有挂技巧)透视最新!wep...
透视挂透视!hhpoker透视... 透视挂透视!hhpoker透视功能如何下载,佛手在线有挂吗,曝光教程(一贯真的有挂);超受欢迎的hh...
透视透视!aapoker可以开... 透视透视!aapoker可以开挂吗,wpk辅助购买,玩家必看科普(有挂方法)是一种具有地方特色的麻将...
透视美元局!红龙poker透视... 透视美元局!红龙poker透视,wepoker辅助透视软件,专业教程(竟然存在有挂),支持语音通讯、...
透视插件!wpk透视脚本视频,... 透视插件!wpk透视脚本视频,wepoker脚本,玩家必备科技(有挂技巧)透视插件!wpk透视脚本视...