Other Load APK

Hello,
I have attached a B4J project, with source, for an APK loader. It interfaces with the standard B4A Bridge. It allows you to install an APK file to a device without opening the B4A IDE and recompiling.

I need this because I want to install an APK on different devices for testing without recompiling. The same thing can be done with the "ADB install" command, but some of my devices do not work with ADB – however, they all work with the B4A Bridge.

NOTE: I just saw something that might be confusing. I have a text entry field showing the hint "APK Path (usually your B4A project Objects folder)". This should be the full path to the actual APK file, not just to the folder. For example: C:\myproject\Objects\myfile.apk

I have left a lot of room for improvement :D.

If you make improvements, please upload and share with everyone.

Barry.
 

Attachments

  • LoadAPK.zip
    249.3 KB · Views: 959
Last edited:

canalrun

Well-Known Member
Licensed User
Longtime User
As I've used LoadAPK, I've added a few features:
  • I added a Disconnect button.
  • I changed the IP and APK text edit fields to combo boxes with a Most Recently Used list.
Barry.
 

Attachments

  • LoadAPK2.zip
    250.6 KB · Views: 794

jmon

Well-Known Member
Licensed User
Longtime User
Thank you for sharing.
I added drag and drop support in the comboBox, so now you can drop links to your APK into it.

You will need the jDragAndDrop library from Agraham : https://www.b4x.com/android/forum/threads/jdraganddrop-library.35754/#content

B4X:
Sub Process_Globals
    '...
    Private DragnDrop As DragAndDrop
    '...
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    '...
    DragnDrop.MakeDragTarget(cmbAPK, "cmbAPK")
    '...
End Sub

Sub cmbAPK_DragOver(e As DragEvent)
    For Each id As String In e.GetDataIds
        If id = "text/uri-list" Then
            Dim Links() As Object = Array As String(e.GetDataObjectForId("text/uri-list"))
            If Links.Length > 0 Then
                For Each link As String In Links
                    If link.ToLowerCase.EndsWith(".apk") Then
                        e.AcceptTransferMode("LINK")
                        cmbAPK.Style = $"-fx-border-color: -fx-focus-color; -fx-border-size: 15;"$
                        Return
                    End If
                Next       
            End If   
            Exit
        End If
    Next
    e.Consume   
End Sub

Sub cmbAPK_DragDropped(e As DragEvent)
    Dim TextLinks As String = e.GetDataObjectForId("text/uri-list")
    If TextLinks <> "" Then
        Dim Links() As String = Regex.Split("\r\n", TextLinks)   
       
        If Links.Length > 0 Then
            For Each Link As String In Links
                If Link.StartsWith("file:/") Then
                    Link = Link.SubString(6)
                End If
                If cmbAPK.Items.IndexOf(Link) = -1 Then       
                    cmbAPK.Items.Add(Link)
                End If   
                cmbAPK.SelectedIndex = cmbAPK.Items.IndexOf(Link)
            Next
        End If
    End If   
    e.SetDropCompleted(True)
    e.Consume
End Sub

Sub cmbAPK_DragExited(e As DragEvent)
    cmbAPK.Style = $"-fx-border-color: none; -fx-border-size: 0;"$
End Sub
 

Attachments

  • LoadAPK2_dragAndDrop.zip
    3.5 KB · Views: 389

koaunglay

Member
Licensed User
Longtime User
jmon said:
Thank you for sharing.
I added drag and drop support in the comboBox, so now you can drop links to your APK into it.

You will need the jDragAndDrop library from Agraham : https://www.b4x.com/android/forum/threads/jdraganddrop-library.35754/#content

B4X:
Sub Process_Globals
    '...
    Private DragnDrop As DragAndDrop
    '...
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    '...
    DragnDrop.MakeDragTarget(cmbAPK, "cmbAPK")
    '...
End Sub

Sub cmbAPK_DragOver(e As DragEvent)
    For Each id As String In e.GetDataIds
        If id = "text/uri-list" Then
            Dim Links() As Object = Array As String(e.GetDataObjectForId("text/uri-list"))
            If Links.Length > 0 Then
                For Each link As String In Links
                    If link.ToLowerCase.EndsWith(".apk") Then
                        e.AcceptTransferMode("LINK")
                        cmbAPK.Style = $"-fx-border-color: -fx-focus-color; -fx-border-size: 15;"$
                        Return
                    End If
                Next      
            End If  
            Exit
        End If
    Next
    e.Consume  
End Sub

Sub cmbAPK_DragDropped(e As DragEvent)
    Dim TextLinks As String = e.GetDataObjectForId("text/uri-list")
    If TextLinks <> "" Then
        Dim Links() As String = Regex.Split("\r\n", TextLinks)  
      
        If Links.Length > 0 Then
            For Each Link As String In Links
                If Link.StartsWith("file:/") Then
                    Link = Link.SubString(6)
                End If
                If cmbAPK.Items.IndexOf(Link) = -1 Then      
                    cmbAPK.Items.Add(Link)
                End If  
                cmbAPK.SelectedIndex = cmbAPK.Items.IndexOf(Link)
            Next
        End If
    End If  
    e.SetDropCompleted(True)
    e.Consume
End Sub

Sub cmbAPK_DragExited(e As DragEvent)
    cmbAPK.Style = $"-fx-border-color: none; -fx-border-size: 0;"$
End Sub
I test your sample . But it doesn't connect my device. How to connect to pc ? There's driver for my device in pc. But there's not show device ip when I click Connect button.
 
Top