androidandroid-intentshareshare-intent

Share text intent prefilled phone number issue


Have written below code to share text in android. Issue i am facing is to prefill the phone number in the sms app.

public static void shareText(final String extraText, final String extraEmail, final String phoneNumber) {
    Intent textShareIntent = new Intent(android.content.Intent.ACTION_SEND);
    textShareIntent.setType("text/plain");
    if (null != extraText) {
        textShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, extraText);
    }
    if (null != extraEmail) {
        textShareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{extraEmail});
    }
    if (null != phoneNumber) {
        textShareIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, new String[]{phoneNumber});
    }
    startActivity(Intent.createChooser(textShareIntent, "Share via"));
}

Solution

  • If I am not wrong, the scenario you are looking for is that you give option on screen to send message(from WhatsApp or SMS) and if it is SMS, it has to prefill the number. As far as I know and researched, you cannot integrate both functionality in one till date as SMS is a standard protocol in mobile and other messaging services like WhatsApp are not(what I mean is they do not support look for SMS protocol An example of messaging app) . What all you can give to give option for SMS where you can open SMS supporting app where in it prefills the number(which is what you require) and messaging which will option other options where in it will open other messaging application(WhatsApp, Telegram). check this