Android Question is there a tool or manual SDK that can match as much JAVA code to B4A code as possible?

xiaoyao

Active Member
Licensed User
Longtime User
is there a tool or manual SDK that can match as much JAVA code to B4A code as possible? For example, run another APP and dynamically add buttons or other controls. It is mainly a few more examples, so that it can be faster and more convenient to convert JAVA code to B4A. Of course, the best approach is to simply insert the JAVA code into the B4A code file without the need for conversion.

like :
PackageManager= this.getPackageManager()
in.Action=intent.setAction
in.Flags =intent.setFlags
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK =Bit.Or(0x04000000, 0x10000000)

Java:
Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
intent.putExtra("LauncherUI.From.Scaner.Shortcut", true);
intent.setAction("android.intent.action.VIEW");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

B4X:
Dim pm As PackageManager
Dim in As Intent = pm.GetApplicationIntent("com.tencent.mm")
in.PutExtra("LauncherUI.From.Scaner.Shortcut", True)
in.Action = "android.intent.action.VIEW"
in.Flags = Bit.Or(0x04000000, 0x10000000)
StartActivity(in)
 

peacemaker

Expert
Licensed User
Longtime User
is there a tool ... that can match as much JAVA code to B4A code as possible?
Yes. Just any text viewer app. Use it for viewing .java files in subfolders of the "Objects\src" folder of your any B4J, B4A project. B4X code is just commented by "//" prefix among Java code lines.

to simply insert the JAVA code into the B4A code file without the need for conversion
It's also easy - just use Inline Java syntax:
B4X:
#if Java
#end if
 
Last edited:
Upvote 0

epiCode

Active Member
Licensed User
useblackbox.io also gave perfect conversion except that bit values were not translated to actual values:

B4X:
    Dim packageName As String = "com.tencent.mm"
    Dim intent As Intent
    intent.Initialize("android.intent.action.VIEW", "")
    
    ' Set the package name to launch the specific app
    intent.SetPackage(packageName)
    
    ' Add the extra
    intent.PutExtra("LauncherUI.From.Scaner.Shortcut", True)
    
    ' Set flags
    intent.SetFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP Or Intent.FLAG_ACTIVITY_NEW_TASK)
    
    ' Start the activity
    StartActivity(intent)
 
Upvote 0
Top