How to send a message in android 2.2? - android

I want to send a message (sms/mms) with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("InvitationSubject", getBaseContext()));
String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
intent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(intent, "Invite friends"));
But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Messaging or other messaging apps.
I saw in the sdk docs there's a new CATEGORY_APP_MESSAGING to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?

Try this code
String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Don't forget to add this <uses-permission android:name="android.permission.SEND_SMS" /> in your manifest.

You can use the type mms-sms, like so
intent.setType("vnd.android-dir/mms-sms");

use following code to send message
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "message subject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
startActivity(Intent.createChooser(shareIntent, "Pick a Share method"));
Gives following permission
<uses-permission android:name="android.permission.SEND_SMS" />

Related

Android share text with link

I have to share text with link.
'Share Text' is followed as.
"Please click this. snapchat://video?param1=text "
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
context.startActivity(Intent.createChooser(intent, "Share"));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_TEXT, Html.html(text));
context.startActivity(Intent.createChooser(intent, "Share"));
All code showed link as general text. It is not acted on SMS or gmail app, etc.
How can I solve this?
You need to use android.content.Intent.
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title goes here")
context.startActivity(Intent.createChooser(intent, "Share"));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
//This line for the link:
intent.putExtra(Intent.EXTRA_TEXT, text);
//This one for text suggestion:
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title goes here")
context.startActivity(Intent.createChooser(intent, "Share"));
It will show as text only as it is not a valid link. Test the link once and try it.

Search for linkedin app in android via intent

I am using intent to get the list of all apps i can post text to. However, linkedin is not appearing in that list. Do i need to do anything extra for linkedin?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "dcsd");
package= mContext.getPackageManager();
List<ResolveInfo> appTargets= package.queryIntentActivities(shareIntent, 0);
I am able to get all other apps like Facebook, Twitter except LinkedIn?
What could be the possible reason?
Code is
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBody = "https://developers.facebook.com/docs/android/share";
intent.putExtra(Intent.EXTRA_TITLE,"Share From Test App");
intent.putExtra(Intent.EXTRA_TEXT,shareBody);
intent.putExtra(Intent.EXTRA_SUBJECT, "hello");
startActivity(Intent.createChooser(intent, "Share With"));
Add this to the intent:
intent.putExtra(Intent.EXTRA_SUBJECT, "dsvs");

How send mms with attach in Android 4.0+

How send mms with attach in Android 4.0+? I try like:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/png");
sendIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse(outputFile.toURL().toString()));
startActivity(sendIntent);
It is work good in htc and samsung, but it is do not work in Nexus 5 (hangouts). I try like:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("address", phonesBuilder2.toString());
sendIntent.putExtra("sms_body", editTextTPMessage.getText());
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(makePicture()));
But file is not attach. I try very much ways, but all ways have problem.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you"); //Version dependent
intent.putExtra(Intent.EXTRA_TEXT, "Hi how are you"); //Version dependent
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/file.gif")));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent,"Send"));

Sending MMS does include the "sms_body"

I am trying to send an image via an MMS using the following code
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "Hi there");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");
It opens the Messaging apps and attach the message but it did not write the "sms_body" which is in my case "Hi there". Why?
try this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intent.putExtra("subject", "subject");
intent.putExtra("sms_body", "Hi there");
intent.putExtra("address", "Phonenumber");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
intent.setType("image/png");
startActivity(intent);
What seems to be working well is I just added EXTRA_TEXT (a solution which #yasserbn provided in a comment):
intent.putExtra(intent.EXTRA_TEXT, default_message);
in addition to:
intent.putExtra("sms_body", default_message);
And it seems to work whether it gets converted to multimedia message or sent as regular SMS.

How to properly handle this intent

I'm trying to have the user e-mail me when they click a button, and use this code to do so. While it works, it brings up a lot of other applications that cant handle e-mail, like Twitter and Facebook. What's missing?
String[] email = {"evan#example.com"};
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_EMAIL,email);
context.startActivity(sendIntent);
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"evan#example.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
startActivity(Intent.createChooser(emailIntent, "Send mail"));
// start the activity
context.startActivity(sendIntent);
// start the activity asking the user how to send the email
context.startActivity(Intent.createChooser(sendIntent, "Email:"));
So you need to remove the last line.
see http://developer.android.com/reference/android/content/Intent.html

Categories

Resources