Search code examples
androidimagesmstabletmms

Attach image to the Messages app programatically


I'm develop an app use mms message of android.

Currently I can:

  1. Send ssm message but not attached image by use following code:

    Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
    smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.putExtra("sms_body", message);
    smsIntent.setData(Uri.parse("sms:" + phoneNumber)); 
    
    ((Activity) context).startActivityForResult(smsIntent, 0);
    
  2. Send attach image via third party app:

    Intent mmsIntent = new Intent(Intent.ACTION_SEND);
    mmsIntent.putExtra("sms_body", "Please see the attached image");
    mmsIntent.putExtra(Intent.EXTRA_STREAM, attached_Uri);
    
    LogUtils.debug(TAG, "extension: " + extension);
    
    mmsIntent.setType(extension);
    ((Activity) context).startActivityForResult(mmsIntent, 0);
    

My problems:

  1. Can't attach image to default messaging app of android.
  2. How can i detect if default messaging app of android device ( such as tablet ) not exist.

So, please guild me on this problem.

Thanks you so much.


Solution

  • Solution for 1st problem

    Intent mmsIntent = new Intent(Intent.ACTION_SEND); mmsIntent.putExtra("sms_body", "Please see the attached image"); mmsIntent.putExtra(Intent.EXTRA_STREAM, attached_Uri); mmsIntent.setType("image/gif"); startActivity(Intent.createChooser(mmsIntent,"Send"));

    Solution for 2nd problem

    You don't have to worry about that, Playstore will. If you are using sms feature you would have given permission. So your app will not be vissible in playstore for SMS featureless devices

    EDIT:

    To include the sender address add an additional EXTRA to the intent mmsIntent.putExtra("address","number_here");