Send an MMS using B4A - question

NJDude

Expert
Licensed User
Longtime User
How do you do something like this on B4A (The forum search is unavailable at this moment)
B4X:
Uri mmsUri = Uri.parse("content://media/external/images/media/1"); 
Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, mmsUri); 
intent.setType("image/png"); 
startActivity(intent);

I can's see how to add EXTRA_STREAM.

Thanks.
 

Vincent HURET

Member
Licensed User
Longtime User
Hi
How to you link the code
Sub SendPhotoMessage(PhoneNumber AsString, Message AsString, Dir AsString, Filename AsString)Dim iIntent AsIntent
iIntent.Initialize("android.intent.action.SEND_MSG", "")
iIntent.setType("vnd.android-dir/mms-sms")
iIntent.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(Dir, Filename)))
iIntent.PutExtra("sms_body", Message)
iIntent.PutExtra("address", PhoneNumber)
iIntent.SetType("image/png")StartActivity(iIntent)End SubSub CreateUri(uri AsString) AsObjectDim r AsReflectorReturn r.RunStaticMethod("android.net.Uri", "parse", ArrayAsObject(uri), ArrayAsString("java.lang.String")) End Sub

To a Button on the application ?

Thanks a lot

Vincent
 
Upvote 0

Simon Smith

Active Member
Licensed User
Longtime User
Hi guys, I followed this, tried both examples, went with the first one and I get a end of program with no error. No intent dialog. I confirm the file 1.png is there as you can see, and it is. What am I doing wrong?


#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

Msgbox(File.DirDefaultExternal,1)
Msgbox(File.Exists(File.DirDefaultExternal,"1.png"),"1")


Dim iIntent As Intent

iIntent.Initialize("android.intent.action.SEND_MSG", "")
iIntent.SetComponent("com.android.mms/.ui.ComposeMessageActivity")
iIntent.setType("vnd.android-dir/mms-sms")
iIntent.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(File.DirDefaultExternal, "1.png")))
iIntent.PutExtra("sms_body", "Hello there!!!")
iIntent.PutExtra("address", "0400THEAUPHONENUMBERDIGITS")
iIntent.SetType("image/png")

StartActivity(iIntent)

End Sub

Sub CreateUri(uri As String) As Object

Dim r As Reflector

Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(uri), Array As String("java.lang.String"))

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Hi
I have tried the following code to have a picture taken by camera and sent by MMS and its ok, sending picture, though the android own MMS UI shows up every time.

PHP:
Sub SendPhotoMessage(PhoneNumber As String, Message As String, Dir As String, Filename As String)
    Dim iIntent As Intent

    iIntent.Initialize("android.intent.action.SEND", "")
    iIntent.setType("vnd.android-dir/mms-sms")
    iIntent.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(Dir, Filename)))
    iIntent.PutExtra("sms_body", Message)
    iIntent.PutExtra("address", PhoneNumber)
    iIntent.SetType("image/png")
    iIntent.SetComponent("com.android.mms/.ui.ComposeMessageActivity")   '''
    iIntent.SetComponent(".ComposeSmsActivity")
  
    StartActivity(iIntent)

End Sub



I am looking for a solution to just press a button and have the picture sent programatically by MMS and/or email, in the background, without user intervention.
Is there a solution for this (paid library or such) ?

Thanks
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I just tried using the method used in this thread to include body text along with the media file using:

B4X:
iIntent.PutExtra("sms_body", "Hi There!")

But sometimes the text will appear in the message and other times it won't - even when using the same device!

So I found this thread:

http://stackoverflow.com/questions/11283085/sending-mms-does-include-the-sms-body

That suggests that adding the below might make the text appear all the time:

B4X:
intent.putExtra(intent.EXTRA_TEXT, "Hi there")

But it seems the Intent object of B4A doesn't support the ".EXTRA_TEXT"
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hey Erel,

Thanks!

But after adding that line, it unfortunately is still not inserting the text reliably. Sometimes yes, sometimes no - very strange issue.

One thing that I noticed is that if I am sending a message to someone where there is *already* a thread in the sms/mms messaging app to that person, then it seems to always insert the text for subsequent messages. But if I am creating a new message thread to a particular person, then it will sometimes work and other times wont insert the text.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…