Android Question Inline Java question

sktanmoy

Active Member
Licensed User
Longtime User
I was trying to use the code below

B4X:
#If JAVA
    public void open_on_instagram(String link){
        Uri uri = Uri.parse("http://instagram.com/p/" + link);
        Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
        likeIng.setPackage("com.instagram.android");
        try {
            startActivity(likeIng);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/p/" + link)));
        }
    }
#End If

But the code wasn't being compiled as Uri class was not found.

I tried to use the code in B4A way but intent class doesn't have any method called setPackage. setComponent didn't give me the desired result.

Can you guys please suggest me what should I do here?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't need this Java code.

B4X:
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "http://instagram.com/p/" & link)
Dim jo As JavaObject = in
jo.RunMethod("setPackage", Array("com.instagram.android")) 'SetPackage will be included in the next update of B4A
StartActivity(in)
 
Upvote 0
Top