I would like to start social apps, Twitter, Facebook, whatsapp etc from my app on API33
Prior to API31, you could use the package manager to check if the app is installed and then start the app.
It is still possible to check if an app exists using the following:
This also requires that the app id is in your manifest:
However, the code to start the app does not work:
Does anyone know how to start an external app, specifically, whatsapp, twitter, instagram and facebook in API 33.
Thanks
Prior to API31, you could use the package manager to check if the app is installed and then start the app.
It is still possible to check if an app exists using the following:
B4X:
public Sub isPackageInstalled(pkname As String) As Boolean
'https://stackoverflow.com/questions/18752202/check-if-application-is-installed-android
Dim ctxt As JavaObject
ctxt.InitializeContext
Try
Dim pkInfo As JavaObject = ctxt.RunMethodJO("getPackageManager", Null).RunMethod("getPackageInfo", Array(pkname, 0))
Return True
Catch
Log(LastException.message)
Return False
End Try
End Sub
log(isPackageInstalled("com.whatsapp"))
This also requires that the app id is in your manifest:
'https://www.b4x.com/android/forum/threads/alternative-to-check-if-whatsapp-is-installed-without-using-packagemanager-query_all_packages-on-sdk30.135863/post-861640 AddManifestText( ):
'https://www.b4x.com/android/forum/threads/alternative-to-check-if-whatsapp-is-installed-without-using-packagemanager-query_all_packages-on-sdk30.135863/post-861640
AddManifestText(
<queries>
<package android:name="com.whatsapp"/>
<package android:name="com.whatsapp.w4b"/>
<package android:name="com.instagram.android"/>
<package android:name="com.twitter.android"/>
<package android:name="com.facebook.katana"/>
</queries>
)
However, the code to start the app does not work:
B4X:
Sub ShareWhatsApp(txt As String)
Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.PutExtra("android.intent.extra.TEXT", txt)
i.PutExtra("android.content.Intent.EXTRA_TITLE", Globals.APPLICATION_TITLE)
i.SetType("text/plain")
i.SetPackage("com.whatsapp")
Try
StartActivity(i)
Catch
MsgboxAsync("There was a problem starting Whats App.",Globals.APPLICATION_TITLE)
' error here is -> java.lang.Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x20001 pkg=com.whatsapp clip={null {...}} (has extras) }
End Try
end sub
Does anyone know how to start an external app, specifically, whatsapp, twitter, instagram and facebook in API 33.
Thanks