Posts

Showing posts from December, 2020

how to convert URI to File Android 10 and above

    how to convert URI to File Android 10 and above how to get file object from URI OR convert URI to file object in android 10 and above versions. some libraries are required File Objects for a process like a retrofit, some image editor e.t.c. to convert URI to file object or anything similar we have a way which is  to support all android old versions and upcoming versions. Step 1: you have to create a new file inside FilesDir which is nonreadable to other Apps with the same name as our file and extension. Step 2: you have to copy the content of the URI to create a file by using InputStream. After these two steps it will return your File object File f = getFile( getApplicationContext (), uri) ; For example  This method provide you file object and it supports all available andoid versions and upcomming version too public static File getFile (Context context, Uri uri) throws IOException { File destinationFilename = new File(context.getFilesDir().getPath() + File.separatorChar