Android Question WhatsApp and Android 9

AlpVir

Well-Known Member
Licensed User
Longtime User
This code allows you to send an image (plus a short text) with WhatsApp :
B4X:
 i.Initialize(i.ACTION_SEND, "")
        i.PutExtra("android.intent.extra.TEXT", "Title " & Title)
        i.SetType("text/plain")
        Dim u As Uri
        u.Parse("file://" & File.Combine(File.DirRootExternal, "xxxxxx.jpg"))
        i.PutExtra("android.intent.extra.STREAM", u)
        i.SetType("image/jpeg")
        Dim jo As JavaObject = i
        jo.RunMethod("setPackage", Array("com.whatsapp"))
        Try
            StartActivity(i)

But it doesn't work with Android 9 !!!

I tried using the "Intent ID" library but was unable to complete the code
B4X:
        Private INTENT As INTENTID
        INTENT.Initialize
        INTENT.ShareImage_WhatsApp (File.DirRootExternal,"xxxxxx.jpg)

I did not find any example of how this library manages to do what is desired.
Warning: I used the INTENT ID library version 1.2 (actually 1.20) which is more recent than version 1.5.
https://www.b4x.com/android/forum/threads/intent-id-share-intents-and-anothers-important-intents.68229/
Thanks in advance for help
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
I have carefully read the suggested documentation but I could not write any code that starts WhatsApp with Android 9 (and attach an image).
B4X:
  i.Initialize(i.ACTION_SEND, "")
        i.PutExtra("android.intent.extra.TEXT", "Orario " & Titolo)
        i.SetType("text/plain")
        Dim u As Uri
        u.Parse("file://" & File.Combine(File.DirRootExternal, NomeImmagine))
        i.PutExtra("android.intent.extra.STREAM", u)
        i.SetType("image/jpeg")
        Dim jo As JavaObject = i
        jo.RunMethod("setPackage", Array("com.whatsapp"))
          StartActivity(i)
And this is my manifest file.
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
AddPermission("android.permission.READ_CONTACTS")
AddPermission("android.permission.GET_ACCOUNTS")
AddPermission(android.permission.READ_PROFILE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)
CreateResourceFromFile(Macro, Core.NetworkClearText)
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

This code works perfectly with Android 8 and below but not with Android 9: it is reported that WhatsApp is not installed!
Any help will be very welcome. Thanks !
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I have carefully read the suggested documentation...
Did you check the example of FileProvider?
Check it and change this lines:
B4X:
Dim u As Uri
u.Parse("file://" & File.Combine(File.DirRootExternal, NomeImmagine))
i.PutExtra("android.intent.extra.STREAM", u)
to this line:
B4X:
i.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileToSend))
 
Upvote 0
Top