当我换一张新照片时,我的代码必须更改照片的名称,但这会使照片名称为“ null”。这是我的代码来创建新名称并创建文件:
public static File createTempImageFile(File storageDir) throws
IOException
{
String timeStamp = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss", Locale.getDefault()).format(new Date());
String imageFileName = "photo_" + timeStamp;
return File.createTempFile(
imageFileName,
".jpg",
storageDir
);
}
这是我将文件添加到存储并将其设置为ImageView的代码:
try {
localFile = createTempImageFile(getExternalCacheDir());
final File finalLocalFile = localFile;
mStorageRef.child("images/" + mRereference).getFile(localFile)
.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Picasso.with(getBaseContext())
.load(Uri.fromFile(finalLocalFile))
.into(mIVpicture1);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.i("Load","" + e);
}
});
} catch (IOException e) {
e.printStackTrace();
}