Android Question Execute bash script?

Dustin Tinsley

Member
Licensed User
Longtime User
I am trying to create a simple app that will run a bash script and then execute an app. The bash script does some downloads behind the scene that updates data for the app. However, I can not get it to work correctly. I know the bash script is functioning correctly because it works properly if I adb into the device and run it that way. Here is what I have thus far:

ADB into device and run: adb shell /sdcard/update.sh - WORKS
Run script from app (code below) - FAILS, DOES NOT GET NEEDED INFO

Here is my code from my Main activity:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Try
        Dim update As Phone
        Dim kodi As Intent
        Dim pm As PackageManager
        update.Shell("sh /sdcard/update.sh", Null, Null, Null)
        Wait(10)
        Msgbox ("Try it now", "")
        Catch
          ToastMessageShow ("Failed to launch app!  Is it installed?", True)
    End Try
    Activity.Finish
End Sub

Sub Wait(Seconds As Int)
   Dim Ti As Long
   Ti = DateTime.Now + (Seconds * 1000)
   Do While DateTime.Now < Ti
      DoEvents
   Loop
End Sub

And here is the code that calls it:
B4X:
Sub Activity_Create(FirstTime As Boolean)

    'This activity is REQUIRED but has to be left alone, you can name it whatever you want
                'but the name MUST match the one in the manifest.
                StartActivity(Main)
                Activity.Finish

End Sub

I just started using B4A so I am sure I have something simple wrong, but can't figure it out..

The bash script I am running does some downloads, then executes another bash script on /sdcard/ but like I said, that all works if I use ADB to execute the script...
 

Dustin Tinsley

Member
Licensed User
Longtime User
I should add I have added these two permissions to the app via manifest editor:

AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
 
Upvote 0

Dustin Tinsley

Member
Licensed User
Longtime User
Never try to block the main thread. It will not work.

Use a timer or CallSubPlus instead.

Why do you need to run a script? You can download whatever needed from your app directly.
Ok, I feel stupid. Worked all weekend on this simple app. Gave up and started over a few times. Woke up this morning to look at your reply and instantly noticed something. I was missing the INTERNET permission! Now, to clean up the code. Like I said, I am new to B4A. What do you mean by "block the main thread"? I am a little lost there.
 
Upvote 0

Dustin Tinsley

Member
Licensed User
Longtime User
The Wait sub should be removed.

Ah, gotcha. Yeah, I already got rid of it. I was using it to determine wait until the script was done but discovered that using "string = update.Shell("sh /sdcard/update.sh", Null, Null, Null)" waited until script was complete.
 
Upvote 0
Top