Android Question file copy

elitevenkat

Active Member
Licensed User
Longtime User
B4X:
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
if Success then

    Dim Dir1 As String = rp.GetSafeDirDefaultExternal("")

    Dim bg As Bitmap = LoadBitmapResize(Dir, FileName, Activity.Width, Activity.Height ,True)
        
    File.Copy(Dir,FileName,Dir1,  FileName)  ------   this line is throwing the error

i get following error

java.io.FileNotFoundException: /storage/emulated/0/Android/data/newkot.com/files/content:/media/external/images/media/34540 (No such file or directory)

Android version 7 samsung j7 max
b4a 7.3 sdk 23


i have included following in mainfest
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"


android:maxSdkVersion="18" />

need help please.
 

Knoppi

Active Member
Licensed User
Longtime User
it looks like the file does not exist

what are the results of:
B4X:
Log( File.Exists( Dir, FileName))
Log( Dir)
Log( Dir1)
Log( FileName)
are the datas valid?
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
Thanks Knoppi for the response.

dir ContentDir
dir1 /storage/emulated/0/Android/data/newkot.com/files
filename content://media/external/images/media/34873
filename content://media/external/images/media/34873


B4X:
Sub chooser_Result (Success As Boolean, Dir AsString, FileName AsString)if Success then
Dim Dir1 AsString = rp.GetSafeDirDefaultExternal("")
Dim bg AsBitmap = LoadBitmapResize(Dir, FileName, Activity.Width, Activity.Height ,True)
 

File.Copy(Dir,FileName,Dir1, FileName) ------ this line is throwing the error  

changed the above as    File.Copy(Dir,FileName,Dir1, "123") works well.

now the problem is to find out the selected file extension and concotinate to "123" file as extn. Exploring...
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
file extension: https://www.b4x.com/android/forum/threads/filebasename-fileextension.76320/#post-484181
your FileName looks like a fullpathFilename if you use it with Dir1 then FileCopy concatinate
Dir1 & FileName = /storage/emulated/0/Android/data/newkot.com/files/content://media/external/images/media/34873 and this is
throwing an error

of course it will throw error. we can use the dir1 path and should give a new file name as target. ( i gave "123"). I further found that the new file can be without extension and the code
B4X:
    Dim Dir1 As String = rp.GetSafeDirDefaultExternal("")
     
    Dim bg As Bitmap = LoadBitmapResize(Dir1, "123", Activity.Width, Activity.Height ,True)
works fine.
 
Upvote 0
Top