I used the following code to send a message "hello" when I say send.
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText().toString());
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
In onActivityResult() :
if(textMatchList.get(0).contains("send")) {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", "Hello");
smsIntent.putExtra("address", "0123456789");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
}
How can I make the app be more flexible. I mean for example if I say "Send this message to mike, Hey man, you want to go to the movie." How can I make the app use only the important information like Send, Mike, and the message itself. And then send the message as usual. Also how make this all possible without hard-coding it.
Are there any tutorials which do this on the net, if so please give me a link, I would really appreciate that.
Thank You
Maybe you might get the text of the recognized speech and use
if(text.contains("Mike")){
//send message to Mike (which i dont know how to do it,i am searching for this )
}
Related
I am creating an application where I can share a link to the applications available in the android devices and increase the share count but I am unable to get any response or onActivityResult for that intent.
For now I have just increased the counter when ever the button is clicked for sharing the link but that's not a correct way to do it.
I am using the below code to share the link
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "\n" + text + "\n\n" + "www.google.com");
shareIntent.setType("text/plain");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(Intent.createChooser(shareIntent, "Share Link using ?"));
Any help is appreciable thank you.
Quoting #CommonsWare in #ndsmyter answer comments
The decision of what happens as part of an ACTION_SEND operation is up
to the other app (and the user), not you. ACTION_SEND is not designed
for use with startActivityForResult(), which is why you are not
getting results, and startActivityForResult() has no bearing on the
behavior of the other app.
So as you see, is not possible :(
Hope this helps!!
I'm develop an app use mms message of android.
Currently I can:
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);
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:
Can't attach image to default messaging app of android.
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 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");
I am writing an application that needs to pre-populate an SMS message with the first name of the contact when using the stock android SMS messenger.
For example if my contacts name is Alex Smith.
When I select Alex Smith to type a message to, I want the text box to already have
'Alex, '
at the beginning of the SMS.
Please how can I achieve that?
Fetch the contact name from contacts, and do like as follows:
String contactName = "Alex"; // get it from selected contact
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", contactName+"," );
startActivity( intent );
Just look over here:
Send SMS via intent
You use a Intent to send the SMS and attach some pre defined text via the EXTRA_TEXT attribute. Quite easy to do. And it works for the normal SHARE intent as well.
You can't change system apps, but you can send "share intent" from your app to SMS App. As you remember, when you push "share" button in some apps, you can share smth with SMS. (You'll have SMS with text that app put in intent). SO, put contact's name in "share intent" and send it to SMS app.
it's bit late, but i hope it will help future users.
void prePopulateSMS(final String mblNumVar, final String smsMsgVar) {
Log.d(TAG, "prePopulateSMS called. smsMsgVar: " + smsMsgVar);
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", mblNumVar);
smsIntent.putExtra("sms_body", smsMsgVar);
startActivity(smsIntent);
}
String number = "0707775544";
Uri uri = Uri.parse(number);
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
smsIntent.putExtra("sms_body", "Hello world!");
startActivity(smsIntent);
When I run this code, Android's default SMS opens up and I can of course send this. My question is: is there anyway I can make the the text "Hello world!" NOT editable, and if you want to write a personal message, it gets below this "Hello world!".
Thanks in advance!
If i got the question right, SmsManager is your solution.
This tutorial might also be usefull.
see this tutorial
http://android10.org/index.php/articlesfullapplications/241-sms-messaging-in-android-send-and-receive
you can customize the layout to disable the part you don't want changed then send the message directly
I have this code to send an emai with an audio attachment that is coming from the raw folder:
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("Audio/basic");
i.putExtra(Intent.EXTRA_SUBJECT, "mySubject");
i.putExtra(Intent.EXTRA_TEXT, "myBody");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://[my_package]/raw/sound"));
startActivity(i);
This code works fine.
I tried to adapt the same code so that I can send MMS message with audio attachment from the raw folder.
I came up with this:
String uri= "mmsto:";
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
i.putExtra("sms_body", "myBody");
i.putExtra("compose_mode", true);
i.putExtra(Intent.EXTRA_STREAM, Uri.parse"android.resource://[my_package]/raw/sound"));
startActivity(i);
The code opens an SMS application. However, there isn't any attachment to the message !
Am I doing it right? Please help me with that.
To those who might be interested:
MMS Functionality is a bit unreliable, not well-documented feature in Android. So, the existed solutions are supposed to work but they will not work all the time on all the devices. You can't depend on them, yet.