我很难简单地重命名由应用程序创建但已放入文档文件夹中的文件。
编辑:
碰巧这些视频不是由应用程序创建的,但预计会由应用程序重命名。用户在开始时手动将视频放入文档文件夹中。我的错。
这是我的代码:
public static boolean renameVideoFile(Context c, File from, File to) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try {
Uri fromUri = FileProvider.getUriForFile(c, c.getPackageName() + ".provider", new File(FileUtils.getVideosDir(), from.getName()));
ContentResolver contentResolver = c.getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Files.FileColumns.IS_PENDING, 1);
contentResolver.update(fromUri, contentValues, null, null);
contentValues.clear();
contentValues.put(MediaStore.Files.FileColumns.DISPLAY_NAME, to.getName());
contentValues.put(MediaStore.Files.FileColumns.IS_PENDING, 0);
contentResolver.update(fromUri, contentValues, null, null);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
} else {
if (from.renameTo(to)) {
removeMedia(c, from);
addMedia(c, to);
return true;
} else …Run Code Online (Sandbox Code Playgroud) 我正在尝试在半径内生成一个点,我得到的值不正确.有人介意看看我经常做错了什么?这是一个在不同问题上发布的公式化方法......
public static Location generateLocationWithinRadius(Location myCurrentLocation) {
return getLocationInLatLngRad(1000, myCurrentLocation);
}
protected static Location getLocationInLatLngRad(double radiusInMeters, Location currentLocation) {
double x0 = currentLocation.getLatitude();
double y0 = currentLocation.getLongitude();
Random random = new Random();
// Convert radius from meters to degrees
double radiusInDegrees = radiusInMeters / 111000f;
double u = random.nextDouble();
double v = random.nextDouble();
double w = radiusInDegrees * Math.sqrt(u);
double t = 2 * Math.PI * v;
double x = w * Math.cos(t);
double y = w * Math.sin(t);
double …Run Code Online (Sandbox Code Playgroud)