Android Question file share problem

HAH

Well-Known Member
Licensed User
I used this code:
B4X:
Sub sharehtml(html As String,filename As String)
    File.WriteString(File.DirInternal,filename,html)
    Dim u As Uri 'ContentResolver library
    u.Parse("file://" & File.Combine(File.DirInternal, filename))
    Dim i As Intent
    i.Initialize(i.ACTION_SEND, "")
    i.SetType("*/*")
    i.PutExtra("android.intent.extra.STREAM",u)
    i.WrapAsIntentChooser("Select")
    StartActivity(i)
End Sub
It work and open apps chose list, but when i select any app, it return error: sharing failed, try again ?
 
Last edited:

HAH

Well-Known Member
Licensed User
Ok, I solved it by replacing DirInternal by DirRootExternal
 

HAH

Well-Known Member
Licensed User
This code is wrong. You must use FileProvider
I tried to use this, but my app crash without error log!
My app is large, so I was think it conflict somewhere with another lib or codes!
But your example is running smoothly!
 

HAH

Well-Known Member
Licensed User
My app works fine without adding this fileprovider code to manifest:
B4X:
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
)

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" />
)
my final manifest code that stop my app without error log:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="21"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

SetActivityAttribute(matjrsalenew, android:windowSoftInputMode, adjustResize|stateHidden)
SetActivityAttribute(matjrreceiptmain, android:windowSoftInputMode, adjustResize|stateHidden)

SetApplicationAttribute (android:supportsRtl, true)
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#F7436A</item>
        <item name="colorPrimaryDark">#F7436A</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>
    <style name="ToolbarMenu" parent="Base.ThemeOverlay.AppCompat.ActionBar">
        <item name="android:textColorPrimary">#fff</item>
        <item name="android:colorBackground">#F7436A</item>
    </style>
</resources>
)


CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)



'fileprovider
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
)

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" />
)
'end of fileprovider
Any suggestion please.
 

DonManfred

Expert
Licensed User
I tried to use this, but my app crash without error log!
There is no such thing in Android. There is no crash without somethig in the LOG! Maybe you need to check the unfiltered log.

But there MUST be a LOG....
Any suggestion please.
Switch to File Provider. It will not work otherwise on newer Androids (7+)
 
Top