Android Question Send SMS Text Message with Image

Discussion in 'Android Questions' started by GeoffT660, Jul 29, 2019.

  1. GeoffT660

    GeoffT660 Active Member Licensed 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.
     
  2. JohnC

    JohnC Well-Known Member Licensed User

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

    Code:
    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))
     
    DonManfred and jimmyF like this.
  3. DonManfred

    DonManfred Expert Licensed 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.
     
  4. JohnC

    JohnC Well-Known Member Licensed 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.
     
  5. JohnC

    JohnC Well-Known Member Licensed 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.
     
    GeoffT660 likes this.
  6. GeoffT660

    GeoffT660 Active Member Licensed 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.
     
  7. JohnC

    JohnC Well-Known Member Licensed User

  8. DonManfred

    DonManfred Expert Licensed User

    No. There is no such thing. A SMS is only TEXT.
     
  9. DonManfred

    DonManfred Expert Licensed User

    You are NOW talking about MMS which is NOT SMS.
    The question was about SMS. SMS is not able to transport an Image.
     
    BillMeyer likes this.
  10. JohnC

    JohnC Well-Known Member Licensed User

    But then the user clarified his question by stating:

    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.
     
    emexes likes this.
  11. DonManfred

    DonManfred Expert Licensed 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...
     
  12. JohnC

    JohnC Well-Known Member Licensed User

    You are NOW talking about money. The OP didn't mention money, so I did not think that was any concern.
     
  13. DonManfred

    DonManfred Expert Licensed User

    If he need to pay for MMS and he did send 1000 MMSses to test this may become any concern.

    Let´s wait what the TO answers...
     
  14. GeoffT660

    GeoffT660 Active Member Licensed 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?
     
  15. DonManfred

    DonManfred Expert Licensed User

    Last edited: Jul 29, 2019
    GeoffT660 likes this.
  16. JohnC

    JohnC Well-Known Member Licensed 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: Jul 29, 2019
    GeoffT660 likes this.
  17. GeoffT660

    GeoffT660 Active Member Licensed User

    Thank you all so much for the suggestions. With a little research, this now works beautifully.:)
     
  18. JohnC

    JohnC Well-Known Member Licensed User

    You're welcome!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice