Android Question How can I convert The following Java code To B4A code? Thanks

269573820

Member
Licensed User
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);
 

269573820

Member
Licensed User
Thank you!Erel!wonderful!It can run!
-----------------------------
B4A:
    ''must add the following code into ManifestText!

'    AddManifestText(
'    <uses-permission
'    android:name="android.permission.QUERY_ALL_PACKAGES"
'    android:maxSdkVersion="34" />
'    )

 

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

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_NEW_TASK =Bit.Or(0x04000000, 0x10000000)
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
You should post a new question on a new thread. This is not related to this thread.

I don't think there is such tool.
The conversion is totally different as the libraries are different.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
B4X:
Sub StartWeChatActivity   
    Dim pm As PackageManager   
    Dim intent As Intent   
    intent = pm.GetApplicationIntent("com.tencent.mm")   
    If intent.IsInitialized Then       
       intent.PutExtra("LauncherUI.From.Scaner.Shortcut", True)       
       intent.Action = "android.intent.action.VIEW"       
       intent.Flags = Bit.Or(0x04000000, 0x10000000) ' FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK
       StartActivity(intent)   
    Else       
       Log("WeChat app is not installed")   
    End If
End Sub
@aeric
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
@aeric and this:

Explanation:​

  1. GetApplicationIntent: Retrieves the intent to launch the specified package (WeChat).
  2. PutExtra: Adds extra data to the intent.
  3. Set Action: Sets the action of the intent to VIEW.
  4. Set Flags: Uses bitwise operations to combine FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK.
  5. StartActivity: Starts the activity with the specified intent.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Very nice!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…