Android Question share text in text

Almora

Well-Known Member
Licensed User
Longtime User
hi..
I can't send the text in the text.
I am using this code. does not send the text inside.


B4X:
Sub Button1_Click

    Dim text As String
    text = (File.ReadString(File.DirAssets, Index1 & ".txt"))


File.Copy(File.DirAssets,text , Starter.shared, text)
    Dim INTENT As Intent
    INTENT.Initialize(INTENT.ACTION_SEND,"")
    INTENT.SetType("text/plain")
    INTENT.SetComponent("com.whatsapp/.ContactPicker")
    INTENT.putExtra("android.intent.extra.TEXT", " ")
    INTENT.PutExtra("android.intent.extra.STREAM", CreateFileProviderUri(Starter.shared, text))

    StartActivity(INTENT)
End Sub
  
  
Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
    Dim FileProvider As JavaObject
    Dim context As JavaObject
    context.InitializeContext
    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
    Dim f As JavaObject
    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
 
Last edited:

Yayou49

Active Member
Licensed User
So that means in your code
B4X:
File.Copy(File.DirAssets,text , Starter.shared, text)
You are trying to copy file 123456789 from dirAsset to starter.shared
Does file 123456789 exists in dir Asset ?
 
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
I'm picking assets..

B4X:
Dim text As String
    text = (File.ReadString(File.DirAssets, Index1 & ".txt"))
 
Upvote 0

Yayou49

Active Member
Licensed User
so that means you do:
B4X:
File.Copy(File.DirAssets,123456789 , Starter.shared, 123456789)

Once again, Does file 123456789 exists in dir Asset ?
 
Upvote 0

Yayou49

Active Member
Licensed User
I know that 1.txt is in your dirAssets.
Just have a look on file.copy parameters description:
File.copy(directory from, File name from,directory to, file name to)

If you put file.copy(dirassets,txt... that means you want to find a file named 123456789
That's why I'm asking if you have a file like this in your dirAssets

BTW, please try this test for me and let me know if it works:
Replace the line
B4X:
File.Copy(File.DirAssets,text , Starter.shared, text)
by
B4X:
File.Copy(File.DirAssets,"1.txt" , Starter.shared, "1.txt")
and
B4X:
INTENT.PutExtra("android.intent.extra.STREAM", CreateFileProviderUri(Starter.shared, text))
by
B4X:
INTENT.PutExtra("android.intent.extra.STREAM", CreateFileProviderUri(Starter.shared, "1.txt"))
 
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
I've tried. sending empty.
1.txt does not send inside
 

Attachments

  • SmartSelectImage_2018-09-17-16-01-43.png
    SmartSelectImage_2018-09-17-16-01-43.png
    231.7 KB · Views: 139
Upvote 0

Yayou49

Active Member
Licensed User
Last chance:

Try

B4X:
Sub Button1_Click

    Dim text As String
    text = (File.ReadString(File.DirAssets, "1.txt"))


'File.Copy(File.DirAssets,text , Starter.shared, text)
    Dim INTENT As Intent
    INTENT.Initialize(INTENT.ACTION_SEND,"")
    INTENT.SetType("text/plain")
    INTENT.SetComponent("com.whatsapp/.ContactPicker")
    INTENT.putExtra("android.intent.extra.TEXT", text)
 '   INTENT.PutExtra("android.intent.extra.STREAM", CreateFileProviderUri(Starter.shared, text))

    StartActivity(INTENT)
End Sub
 
 
'Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
'    Dim FileProvider As JavaObject
'    Dim context As JavaObject
'    context.InitializeContext
'    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
'    Dim f As JavaObject
'    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
'    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))'
'End Sub
 
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
this code works, but it doesn't work on android8+.
I did not test. I guess it won't work
 

Attachments

  • SmartSelectImage_2018-09-17-16-46-37.png
    SmartSelectImage_2018-09-17-16-46-37.png
    148.9 KB · Views: 134
Upvote 0
Top