0

I have a requirement in my application in which I have to send MMS on click of button. When I click on the button it prompts to choose using which application I want to complete the action either email or messaging. I want it to open by default with messaging. I searched a lot but couldn't get any answer. Below, I am posting my code:

public class MMSActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button mms = (Button)findViewById(R.id.mms);
    mms.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            sendMMS();
        }
    });
}

public void sendMMS() {
    Intent in = new Intent(Intent.ACTION_SEND);
    in.putExtra("sms_body", "some text");
    in.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath().toString()+"/diplomat/ALEXANDRA-1339242345022.jpg")));
    in.setType("image/jpeg");
    startActivity(in);
    Log.d("MMS", "SendMMS called");
}
}

I even tried with setting class as android.telephony.SmsMessage but it didn't worked.

Nitish
  • 3,097
  • 13
  • 45
  • 80

2 Answers2

1

I want it to open by default with messaging

First, it is unclear what you think "messaging" is. I will assume that you mean the Android open source project (AOSP) MMS client.

Second, many devices do not have this app. Device manufacturers are welcome to use whatever MMS client they wish, which may or may not be the AOSP client.

Third, users are welcome to install and use their own SMS/MMS clients that they obtain from the Play Store or elsewhere. By saying that users should not have a choice in the matter, you are saying that you are more important than your users. Your users will tend to disagree.

Please allow your users to use whatever MMS client they wish, and at least one that actually exists.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sorry Sir, but this is my client's requirement. He wants MMS to be sent without prompting for any choice. He wants that on click of MMS button, new screen should open that will allow him to enter receipient's number, text message in message box and the image that he intends to send, in the same way as we see when we share image from gallery using mms. That's why, I used messaging. May be, I am having some misconception. Is it possible to do this? – Nitish Jun 11 '12 at 11:43
  • @nitish: "this is my client's requirement" -- that does not make it possible in a reliable fashion. – CommonsWare Jun 11 '12 at 11:47
  • OK, and do I need to provide additional permission in manifest for sending mms? I asked this stupid question because when I tested my application, it got struck in sending. Still reciepient didn't received the message. – Nitish Jun 11 '12 at 11:48
  • 1
    @nitish: If you are using `SmsManager` to send SMS, you need the `SEND_SMS` permission. If you are using `startActivity()`, as you show above, you do not need `SEND_SMS`, as some other app is actually sending the message. – CommonsWare Jun 11 '12 at 11:51
0

If you are sending image.

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
        sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
        sendIntent.putExtra("sms_body", "some text"); 
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image_4.png"));
        sendIntent.setType("image/png");
        startActivity(sendIntent);; 
Harshid
  • 5,701
  • 4
  • 37
  • 50