Android Question Uploading Image from Camera to SQl lite Database

Makumbi

Well-Known Member
Licensed User
Good morning how can i improve this code to insert data in my sqlite database
what B4a libraries can i use if iam to use this kind of code

B4X:
Dim fd As FileDialog
Dim fileList As List
fd.FastScroll = True

fd.FilePath = File.DirRootExternal&"/DCIM"
ret = fd.Show("B4A File Dialog", "Yes", "No", "Maybe", Bmp)

If fd.ChosenName <> "" Then
File.MakeDir(File.DirRootExternal , "images")
File.Copy(fd.FilePath,fd.ChosenName,File.DirRootExternal & "/images",fd.ChosenName)
Else
Msgbox("You have not selected any file","Select file")
End If
 

Makumbi

Well-Known Member
Licensed User
My Table has another filed called photo so want to get the photo take using the phone camera and upload it to the the SQL lite database and then after view it on my layout page( i Want to browse my Phone Gallery and get that particular photo and upload to my Database so that i can easily see it when i click on the profile setting of my app

how can i insert a code which can browse phone gallery and then get that particular picture

B4X:
sm.Initialize(Activity, Me, "SlideMenu", 42dip, 180dip)
    sm.AddItem("Profile", LoadBitmap(File.DirAssets, "bomb.png"), 1)
    sm.AddItem("Register", LoadBitmap(File.DirAssets, "book_add.png"), 2)
    sm.AddItem("Accounts", LoadBitmap(File.DirAssets, "book_open.png"), 3)
    sm.AddItem("Academics", LoadBitmap(File.DirAssets, "wrench.png"), 4)
    sm.AddItem("Simple Chat", LoadBitmap(File.DirAssets, "wrench_orange.png"), 5)
    sm.AddItem("Get Updates", LoadBitmap(File.DirAssets, "bomb.png"), 6)
    sm.AddItem("School Events",LoadBitmap(File.DirAssets, "book_open.png"), 7)

Where is the SQLite database? Which profile picture?
B4X:
If CCode.Text = "" Or Phone.Text = "" Or Emails.Text = "" Then
        Msgbox("You have to enter all fields","Missed data field")
    Else
        'cursor1 = SQL1.ExecQuery("SELECT * FROM Register where Phone = '" & Phone.Text & "' ")
        cursor1 =SQL1.ExecQuery2("SELECT * FROM Register where Phone = ?", Array As String(Phone.Text))
        If cursor1.RowCount<>0 Then
            'user registered
            For i = 0 To cursor1.RowCount - 1
                'cursor1.Position = i
                Msgbox("You are Already Registered","SMIS")
            Next
        Else
            'user not registered
            DBloadnew
     End If
     End If
End Sub
Sub DBloadnew
cursor1 = SQL1.ExecQuery("SELECT ID FROM Register")
If cursor1.RowCount > 0 Then
    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = i
        Dim NewID As Int
        NewID = cursor1.GetInt("ID")
    Next
End If
NewID = NewID +1 '
SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "','" & NewID & "')")
'SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "')")
Msgbox("Registration Completed Successfully","SMIS")
 
Upvote 0

WebQuest

Active Member
Licensed User
Instead if you want to select an image from the device I used this method, once you acquire the image in the bitmap variable you can use it I save it wherever you want. ;)





B4X:
Sub Process_Globals
  
   Dim Chooser As ContentChooser
  
End Sub


B4X:
Sub BTAggImage_Click

    Chooser.Initialize("chooser")
    Chooser.Show("image/Camera", "Select an image")
    ToastMessageShow("Select Image",True)
 
End Sub


Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
  
    If Success Then
        TempBitmap = LoadBitmap(Dir,FileName)
        TempBitmap=CreateScaledBitmap(TempBitmap,1920,1080)
        ImageViewResult.SetBackgroundImage(TempBitmap)
        ImageViewResult.Gravity=Gravity.FILL
    Else
            ToastMessageShow("No image selected", True)
    End If
  
  End Sub
 
Last edited:
Upvote 0
Top