Android Question Send SMS Text Message with Image

GeoffT660

Active Member
Licensed User
Longtime User
Is it possible to send a SMS Text message with a .jpg Image that is stored on the device from within B4A? Similar to if you take a picture from within messaging and send it.
 

JohnC

Expert
Licensed User
Longtime User
Something like this should work - also look at other samples in this forum to send SMS using an intent:

B4X:
iIntent.Initialize("android.intent.action.SEND", "")   
iIntent.SetType("image/*")
iIntent.PutExtra("android.intent.extra.STREAM",  GetFileUri(File.DirRootExternal, "test.jpg"))
iIntent.PutExtra("address", TelNum)
iIntent.PutExtra("sms_body", SMSText)
iIntent.PutExtra("android.intent.extra.TEXT", SMSText)

Dim JO As JavaObject
JO.InitializeContext
JO.RunMethod("startActivity", Array(iIntent))
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I don´t think this will work. SMS has a limited Size. Not sure about exactly but i think 160 chars or so when using 7bit characters. 120 or so otherwise.
Point is:
- that a SMS is ONLY TEXT.
- The image must be encoded in base64 to send it as a SMS.
- Every picture is too big to get encoded in 160 chars.
- Such an encoded Picture will receive at the other side (destination) as TEXT (the base64 String).
- No SMS App does decode it to a Bitmap.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hey Don,

It uses an Intent to open the users default SMS app, which is typically also their MMS app, which can handle images no problem.

One of my app's uses code similar to above, so I know for a fact it works.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But I do want to clarify one thing to the OP, unless your app is designed to replace the default SMS/MMS app on the user's device, your B4A app (or any other app) can not send an SMS/MMS message directly from the app itself. This is a rule setup by Google.

The only workaround is to send the SMS/MMS message via an Intent (like my example code does) that will open the users default SMS/MMS app and then the user needs to click "Send" in their messaging app to actually send the message.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
How are images retrieved and sent in a message accomplished? Is this currently possible to send any image in a text message in B4a? If so please provide a link or further explanation. Thanks.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You are NOW talking about MMS which is NOT SMS.
The question was about SMS. SMS is not able to transport an Image.

But then the user clarified his question by stating:

Similar to if you take a picture from within messaging and send it.

So, that lead me to believe he wasn't just talking about strictly using only SMS, that he was also talking about MMS (which nowadays the SMS/MMS is the same app) because with a strictly SMS messaging app, you couldn't "take a picture from within messages and send it".

So, that's why I said he can do it with my code because it will work on the majority of phones out there because they all handle MMS too.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I, for example, can send unlimited SMS. I usually use 1 to 5 SMS-Sendings; SMS is out :D

But for every MMS i have to pay. This may apply to ither phoneproviders too. Maybe not.
I do not use MMS because of this.

But no problem in these days of Whatsapp und co, High amount of Mobile data...
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I, for example, can send unlimited SMS. I usually use 1 to 5 SMS-Sendings; SMS is out :D

But for every MMS i have to pay. This may apply to ither phoneproviders too. Maybe not.
I do not use MMS because of this.
You are NOW talking about money. The OP didn't mention money, so I did not think that was any concern.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Thanks for all the input and sorry if I didn't understand SMS/MMS. I am now able to send the text message after choosing a program but get an error when trying to send the image. I think the relevant part of the error is this.
Caused by: android.os.FileUriExposedException: file://storage/emulated/0/Android/data/com.bizmobl/files/images/U1000.jpg exposed beyond app through ClipData.Item.getUri()

I have tested that the file exists. Is this a permissions issue or something else?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I would first install and get the sample working in my post #7.

That will provide you a lot of the code you need and teach you both about file providers and sharing a file via an Intent.

From there you should be able to switch it to sharing with your SMS/MMS app using my code in post #2.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You're welcome!
 
Upvote 0
Top