Please help seupt b4a app as Custom URL

BarrySumpter

Active Member
Licensed User
Hi all,
I've researched for hours trying to find a way to execute a Basic4Android app via a Custom URL / url namespace.

The following discusses how to do it correctly in Android
(i.e. NOT a custom URL but better for android this way):

java - How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS? - Stack Overflow

Where I can execute my b4a app from any browser or language like the following:

B4X:
    Dim i As Intent
   
   TheLink = "MySuperCoolB4Aapp://test me: " & mAllMyParams 

   i.Initialize(i.ACTION_VIEW, TheLink)

   StartActivity(i)

Unless there is a way to do this already in b4a settings?

Any help would be greatly appreciated.


tia
 
Last edited:

NJDude

Expert
Licensed User
The attached project does what you're looking for.

This sample will prompt you to select an app everytime it detects "www.basic4ppc.com", in this case you will see this app (Generic Sample) and Internet, you might see more if you have more than 1 browser installed on your device, if you click on this app (Generic Sample) it will play a YouTube video.

Let me explain how I did it:

1- You need to add these lines to the AndroidManifest.xml
B4X:
<activity android:name=".UriActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> 
<data android:scheme="myapp" android:host="path" />
</intent-filter> </activity>
2- Using the Manifest Editor (from the IDE click on Project -> Manifest Editor) enter this text:
B4X:
AddActivityText(test,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="www.basic4ppc.com"/>
</intent-filter>)
Details:

- "test" : Is the name of the activity you want to execute.
- android:scheme="http" : In this case I'm using http to quickly explain the process, you can replace that with "MySuperCoolB4Aapp" as you indicated in your post.
- android:host= : The domain where you have your custom URLs defined, you should replace that with the URL to your website.

That's it.
 

Attachments

  • CustomLinkSample.zip
    6.6 KB · Views: 364
Upvote 0

BarrySumpter

Active Member
Licensed User
If I could clarify...

I currently have an Android app on my physical device named
MyBarcodeReader.b4a
which uses my physical android device camera to
read a barcode and displays the barcode number
on my phisical android device.

I have another Android app on my physical device named
Execute_MyBarcodeReader.b4a
that calls/Executes the Android app BarcodeReader.b4a
on my physical device.

So I am NOT calling anything on the web.
Its all on the Android physical device.


----
Within the calling app named Execute_MyBarcodeReader.b4a
i would have a slight variation of the script I posed originaly:

B4X:
Dim i As Intent
TheLink = "MyBarcodeReader://"      '  just the call/link - no params
i.Initialize(i.ACTION_VIEW, TheLink)
StartActivity(i)


To me that sould be all thats needed for the calling app.

I should also be able to use the default Android browser
and enter the address:
MyBarcodeReader://
Which would execute the called app named MyBarcodeReader.b4a on my physical android device


-----

Now for the receiving / called app named MyBarcodeReader.b4a

I'm hoping one of the items you posted
will identify the called app named MyBarcodeReader.b4a
as a custom URL to my Physical Android device.

But I don't know which item 1 or 2 you posted
to use in the AndroidManifest.xml of my app named MyBarcodeReader.b4a

-----

Now that I've read thru this for the 20th time
perhaps the suggestions made in the hyperlink
I posted in my original post
were trying to tell us that we
SHOULD NOT introduce a NEW scheme
called 'MyBarcodeReader://'

But to stay with the normal scheme of "http://"
And use the
android:host="www.basic4ppc.com"
or in my case
android:host="MyBarcodeReader"
to qualify the intent.


And that item 1 is added to the AndroidManifest.xml via a 3rd party text editor
And that item 2 is added using the Project | manifest editor.


So now I'm thinking my calling app should have the following script:

??????

B4X:
Dim i As Intent
TheLink = "http://MyBarcodeReader"      '  just the call/link - no params
i.Initialize(i.ACTION_VIEW, TheLink)
StartActivity(i)

And within the AndroidManifest.xml of the called android app named MyBarCodeReader.b4a:

B4X:
         <intent-filter>
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="android.intent.category.BROWSABLE" />
         <data android:scheme="http" android:host="myBarCodeReader"/>
         </intent-filter>


Any further assistance in how to further modify the xml file script
AND how to further modify the manifest script via the manifest editor
would be greately appreciated.

tia
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
The GenericSample didn't work until I changed the
test in
AddActivityText(test,
to Test
AddActivityText(Test,
via the Project | Manifest Editor.

Thaks for posting that example.

If you can spare the time to assist with my clarification above
I'd certainly appreciate any thoughts.
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Try changing this line:

From:
B4X:
<data android:scheme="http" android:host="myBarCodeReader"/>

To:
B4X:
<data android:scheme="MyBarcodeReader"/>

See if that does what you need.

NOTE: The 'test' works for me, I don't know what you had to change it to 'Test'
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Thanks for that.
Yes, that certainly helped.
And thanks so much for getting me started in the right direction.

GenericSample.b4a
include ABZxing - barcode reader library

Main Module - no code really - does nothing
B4X:
'Activity module

Sub Process_Globals
  
         'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
                    

End Sub

Sub Globals
    
       'These global variables will be redeclared each time the activity is created.
       'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause(UserClosed As Boolean)

End Sub

'##########################
'######## Controls ########
'##########################

'##########################
'######## Routines ########
'##########################
Test module - pretty simple just 7 lines of script in the right places:
B4X:
'Activity module
Sub Process_Globals
       'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
End Sub

Sub Globals
       'These global variables will be redeclared each time the activity is created.
       'These variables can only be accessed from this module.

  Dim myABBarcode As ABZxing
  Dim TheLink As String

End Sub

Sub Activity_Create(FirstTime As Boolean)

    myABBarcode.ABGetBarcode("myabbarcode", "")

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
'ExitApplication  -  does not function correctly here barcode reader won't fire
End Sub

Sub myABBarcode_BarcodeFound (barCode As String, formatName As String)
    
    Dim i As Intent
    TheLink = "webme://test me: " & barCode ' this works with an app that has a custom URL of webme
    i.Initialize(i.ACTION_VIEW, TheLink)
    StartActivity(i)
    
  ExitApplication   '   I don't think this is really exiting properly here
                          ' my webme custom url app does fire and has the barcode number properly
                          ' I then press the backbutton to exit my webme app 
                          ' but the barcode reader fires again instead of exiting.
End Sub
Manifest Editor - please note the AddActivityText(Test, section
and the <data android:scheme="myapp"/> script line
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136

AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true" 
                  android:normalScreens="true" 
                  android:smallScreens="true" 
                  android:hardwareAccelerated="true" 
                  android:anyDensity="true"/>)
                  
SetManifestAttribute("android:installLocation", "auto")                  
                  
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

AddActivityText(Test,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp"/>
</intent-filter>)

'End of default text.



Whewh!
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
The barcode app will keep running, you are opening a different app you cannot close it from your app.

What B4A version you have?, you can post the whole project if you want, from the IDE click on File -> Export to ZIP.

So, does your app now works the way you wanted?
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
I just need to know the correct place to exit the
GenericSample.b4a barcode app
so that it will be removed from memory and not woken up when I exit my webme app.

tia

I'm running 1.9 which is the latest at this time.

I wanted to note the code so others could see how simple it was and not have to go thru hours of trial and error like I did.

I'll post the full app as soon as we figure out how to get the GenericSample.b4a barcode app to remove itself from memory.
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
http://www.basic4ppc.com/forum/basi...ons/10915-way-get-exit-application-event.html

....
If the user presses on the home screen, or on the back key, or starts a new application then Activity_Pause will be called.
....

Yesh ok, android won't release the process thread.
You have to back out of the process thread.

I could write to a specific file to leave a message for the calling app.
But then the calling app would have to know the called app has finished.
If there is not a message event then the calling app would have to monitor that message file for an update.
and on and on and on and ...

Looks like I can url forward with parameters.
But can't backout with notifications.
Bummer.
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Hours n hours spent on this.
Still can't get it to work like I want it to.

I just want the BGSBarCodeApp to scan a barcode and save it to a file on the SDCard.

Launch URL (all one line):
BGSBarCodeApp://Path:/mnt/sdcard/BGSBarCodeLauncher/&File:BGSBarCodeLauncher.txt&DTStamp:2012-04-13%2009:48:55&Key:BarCode=

Seperated for readability:
BGSBarCodeApp://
Path:/mnt/sdcard/BGSBarCodeLauncher/
&File:BGSBarCodeLauncher.txt
&DTStamp:2012-04-13%2009:48:55
&Key:BarCode=

BGSBarCodeApp is the Custom URL Name
Path is the name of the Launcher app AND Path under the sdCard where I want to save the BarCode File
File is the name of the .txt file where I want to save the Barcode data into
DTStamp is kinda my recID
Key:BarCode=xxxx is where I want the actual Barcode. - xxxx is either a number or the word Cancel

In the attached app
If I UN-comment the msgBox script the BGSBarCodeApp will work like I want it to.
i.e. BarScan only once and does actually save the file and its data as expected.

But, if I comment OUT the msgBox scripts so that I have NO msgbox popups - the BGSBarCodeApp acts a bit flaky.
i.e. BarScans twice and doesn't save the file and its data on Cancel(back button).

Any positive constructive help would be greatly appreciated.

http://barrysumpter.com/ABBarcode Test Orig 5.zip
http://barrysumpter.com/ABBarcode Launcher.zip

tia

update in next post
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
update:

If anyone is interested:
Install the BarCode Test first.
It's designed to work with the Launcher only.
It will install with just a blank screen.
(If anyone has a suggestion on how to install without the blank screen I'd like to know how.)
So will just sit there until you press the back button.

Then install the Launcher.
Touch the button and the BarCodeTest app will execute.

Its been reported there is an error of Folder does not exist.
So i'll fix that but you can still test if you want.

On my phone, the barcode app is still taking two scans on first run.
Any subsequent launch and it will take the proper single scan.

Its been reported by another b4a deveoper
that the double scan on first execution
is NOT happening on their phone.

I'd appreciate any test results from others.

tia
 
Last edited:
Upvote 0
Top