Android Question Link in a webview dont open an app

asap74

Member
Licensed User
I open a web Page by a webview.
In the HTML i ve a link (a href) that point to an Istagram profile.
I would like to open Istagram app at the selected profile.
In Chrome It works, in the webview It opens the Istagram website.

I ve also tried something like this (googling stack overflow).
<a href="fb://profile/fbID">Facebook</a>
<a href="twitter://user?screen_name=username">Twitter</a>

Is maybe something related to manifest?
Is It a good idea to have a button outside webview to open Istagram app if istalled?

Hoping to have explained the problem clearly.
Thank you.
 

asap74

Member
Licensed User
hi and thank you!
maybe we are talking about "intent", i found a tutorial on this forum:

https://www.b4x.com/android/forum/threads/intent-for-beginner-messages-between-apps.123680/#content

i try to write this:
Private Sub Button1_Click
Dim intent1 As Intent
intent1.initialize(intent1.ACTION_VIEW,"https://instagram.com/blahblah=")
intent1.setpackage("com.instagram.android") 'target app package name
intent1.setType("text/plain") 'mime types ex: text/plain
'intent1.PutExtra("android.intent.extra.*","your message content data")
StartActivity(intent1)
End Sub

in your example the manifest contains:
AddActivityText("main",
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="http" />
<data android:host="mydomain.myd" />
</intent-filter>

and this:
android:targetSdkVersion="14"

i haven't modified my manifest.

i've also read your article.

my code crash the app when i click the button.

this is the first step: click a sinple button and open istagram.

currently it's not working.

thank you.
 
Upvote 0

asap74

Member
Licensed User
i solved this way, any comment to improve is welcome! thank you to all!

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    WebView1.LoadUrl("www")
    WebView1.ZoomEnabled=False
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub WebView1_OverrideUrl (Url As String) As Boolean
    If Url.ToLowerCase.StartsWith("https://instagram.com") Then
        Dim intent1 As Intent
        intent1.initialize(intent1.ACTION_VIEW,"https://instagram.com/XXX?igshid=XXX=")
        intent1.setpackage("com.instagram.android") 'target app package name
        'intent1.setType("text/plain") 'mime types ex: text/plain
        'intent1.PutExtra("android.intent.extra.TEXT","your message content data")
        'intent1.SetComponent("com.instagram.android/.activity.ShareHandlerActivity")
        StartActivity(intent1)
    Else
        WebView1.LoadUrl(Url)
    End If
    Return True
End Sub
 
Upvote 0
Top