Java 在android中创建文件路径
在剪辑库中现有图像时编码Java 在android中创建文件路径,java,android,database,firebase,sqlite,Java,Android,Database,Firebase,Sqlite,在剪辑库中现有图像时编码 final Uri uri = result.getUri(); StorageReference thumb_filepath = mStorage.child("Raw").child(UID + ".jpg"); File thumb_filePath = new File(uri.getPath()); Log.d("DFGHJKFGHJ", "CREATED FILEEEE" + thumb_filePath); Logcat结果 现在,我使用相同的
final Uri uri = result.getUri();
StorageReference thumb_filepath = mStorage.child("Raw").child(UID + ".jpg");
File thumb_filePath = new File(uri.getPath());
Log.d("DFGHJKFGHJ", "CREATED FILEEEE" + thumb_filePath);
Logcat结果
现在,我使用相同的方法从firebase获取图像,并将其转换为uri和文件,但输出不同
代码
Uri uri = null;
uri = Uri.parse(String.valueOf(url));
Log.d("DFGHJKFGHJ", "CREATED URI : " + uri);
File thumb_filePath = new File(uri.getPath());
Log.d("DFGHJKFGHJ", "CREATED FILEEEE" + thumb_filePath);
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Folder_name";
File folder = new File(path);
if (!folder.exists()) {
folder.mkdir();
}
Uri uri = Uri.fromFile(folder);
File thumb_filePath = new File(uri.toString());
assertEquals(folder.getAbsolutePath(), thumb_filePath .getAbsolutePath());
正在创建URI,但文件的输出为
02-23 13:50:48.326 11130-11130/com.appmaster.akash.messageplus D/DFGHJKFGHJ: CREATED FILEEEE/v0/b/messageplus-cd647.appspot.com/o/hackerpic.jpg
因此,下一个功能也不起作用。那么,有谁能帮我获得firebase图像的第一个输出吗?创建自己的路径并保存文件
Uri uri = null;
uri = Uri.parse(String.valueOf(url));
Log.d("DFGHJKFGHJ", "CREATED URI : " + uri);
File thumb_filePath = new File(uri.getPath());
Log.d("DFGHJKFGHJ", "CREATED FILEEEE" + thumb_filePath);
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Folder_name";
File folder = new File(path);
if (!folder.exists()) {
folder.mkdir();
}
Uri uri = Uri.fromFile(folder);
File thumb_filePath = new File(uri.toString());
assertEquals(folder.getAbsolutePath(), thumb_filePath .getAbsolutePath());
从firebase存储下载图像并在本地保存:
private void downloadImgFromFStorageToLocalFile(StorageReference fileRef) {
if (fileRef != null) {
progressDialog.setTitle("Downloading...");
progressDialog.setMessage(null);
progressDialog.show();
try {
final File localFile = File.createTempFile("images", "jpg");
fileRef.getFile(localFile).addOnSuccessListener(new
OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot
taskSnapshot) {
Bitmap bmp =
BitmapFactory.decodeFile(localFile.getAbsolutePath());
imgViewProfile.setImageBitmap(bmp);
progressDialog.dismiss();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, exception.getMessage(),
Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new
OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot
taskSnapshot) {
// progress percentage
double progress = (100.0 *
taskSnapshot.getBytesTransferred()) /
taskSnapshot.getTotalByteCount();
// percentage in progress dialog
progressDialog.setMessage("Downloaded " + ((int) progress)
+ "%...");
}
});
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "File ref is null",
Toast.LENGTH_LONG).show();
}
}
private void下载imgfromfstoragetoLocalFile(存储参考文件ref){
如果(fileRef!=null){
progressDialog.setTitle(“下载…”);
progressDialog.setMessage(空);
progressDialog.show();
试一试{
最终文件localFile=File.createTempFile(“图像”、“jpg”);
fileRef.getFile(localFile).addOnSuccessListener(新建
OnSuccessListener(){
@凌驾
成功时公共无效(FileDownloadTask.TaskSnapshot
任务快照){
位图bmp=
BitmapFactory.decodeFile(localFile.getAbsolutePath());
imgViewProfile.setImageBitmap(bmp);
progressDialog.disclose();
}
}).addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常){
progressDialog.disclose();
Toast.makeText(MainActivity.this,exception.getMessage(),
Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(新版本)
OnProgressListener(){
@凌驾
public void onProgress(FileDownloadTask.TaskSnapshot
任务快照){
//进度百分比
双进度=(100.0*
taskSnapshot.GetByTestTransferred())/
taskSnapshot.getTotalByteCount();
//“进度百分比”对话框
setMessage(“下载的”+((int)进度)
+ "%...");
}
});
}捕获(IOE异常){
e、 printStackTrace();
}
}否则{
Toast.makeText(MainActivity.this,“文件引用为空”,
Toast.LENGTH_LONG).show();
}
}
我认为您不需要删除uri.getPath()
,而是创建自己的路径,然后将uri保存到该路径。所以我必须首先将图像下载到本地存储?请你也给我看看好吗。教程有点混乱,文件pathlocalFile.getAbsolutePath()在哪里