ShareActionProvider - send string with link - android

Couldn't find the answer to my problem, so here is my question:
I have an app storing debts and where i can send the debt info to anyone using ShareActionProvider in the actionbar. It all works fine, i can send a string via, let's say, whatsapp. So far, so good. I wanted to include a link to the app in the play store at the end of the message but couldn't find out how to do it.
Here the intent I'm sending via the ShareActionProvider
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message);
i.setType("text/plain");
How can i achieve to add something like this:
Don't forget to check out this

just append the link to the end.
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=" + getPackageName());
i.setType("text/plain");

Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, share_message + " https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
i.setType("text/plain");

Related

Send a text message from my android application to Whatsapp to specific Contact

I'm trying to send a text message from my android application to Whatsapp to specific Contact. when I'm using below codes, I am succeed either to send message and have to pickup contact manually, or If Specific number chat window opens, but message is blank. So is it possible to do both with one intent ? Here is my code:
I can share message to WhatsApp, but contact i have to choose manually:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.setPackage("com.whatsapp");
i.putExtra(Intent.EXTRA_TEXT, "Hello World");
try {
activity.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
Specific number in wats app window opens, but message is blank:
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", "smsText");
i.setPackage("com.whatsapp");
activity.startActivity(i);
Below code will helps you :
String strMessageToShare=YourEditText.getText().tostring();
final Intent myIntent = new Intent(
android.content.Intent.ACTION_SEND_MULTIPLE);
myIntent.setType("text/plain");
myIntent.putExtra(android.content.Intent.EXTRA_TEXT,
new String[]{strMessageToShare});
YourActivity.this.startActivityForResult(Intent
.createChooser(myIntent, "Sharing message..."), 1);
This is what works for me.
The parameter 'body' gets not read by the whatsapp app, use 'Intent.EXTRA_TEXT' instead.
By setting the 'phoneNumber' you specify the contact to open in whatsapp.
Intent sendIntent = new Intent(Intent.ACTION_SENDTO,
Uri.parse("smsto:" + "" + phoneNumber + "?body=" + encodedMessage));
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

Share intent location

I've been trying to send a location via share intent through whatsapp, my code so far:
String uri = "geo:" + currentLoc.getLatitude() + "," +currentLoc.getLongitude() + "?q=" + currentLoc.getLatitude() + "," + currentLoc.getLongitude();
Intent i=new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
The problem is that when the app chooser opens it only shows "google maps" and "waze". How do I can modify it so I can send it by many other apps that support location like whatsapp or facebook?
You need to replace android.content.Intent.ACTION_VIEW by Intent.ACTION_SEND or Intent.ACTION_SEND_MULTIPLE.
You can find the full information about sending and receiving data between apps here.
Finally, you need to open the Intent like this:
startActivity(Intent.createChooser(shareIntent, "Share via"));
instead of: startActivity(shareIntent); as explained here. This will create an dialog for user to choose which application wants to use for sharing.
EXAMPLE CODE:
String uri = "http://maps.google.com/maps?saddr=" + location.latitude + "," + location.longitude;
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, uri);
startActivity(Intent.createChooser(sharingIntent, "Share in..."));
Try to use the code below, this is an example from official documentation.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my location to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.share, menu);
MenuItem item = menu.findItem(R.id.share_item);
actionProvider = (ShareActionProvider) item.getActionProvider();
// Create the share Intent
String shareText = URL_TO_SHARE;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
actionProvider.setShareIntent(shareIntent);
return true;
}
Another option you can directly specify app to open your intent by adding package name to your intent.
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
Please, for more info check docs whatsapp and android.

Chooser is not working

in my app i want to display the location using map and also browsers(i need to display what are all the browser that installed in the device.) using the Chooser.please any one help me to find a solution.Thanks in advance. and also i need to set that always just once button in it.....
String format = "geo:0,0?q=" + Double.toString(latter)
+ "," + Double.toString(longer) + "(" + sender
+ ")";
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(Intent.createChooser(intent,
"Complete action using"));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
Use the below link as an example to implement chooser in android https://github.com/iPaulPro/aFileChooser

Send SMS to multiple recipients via Intent

I am trying to send SMS to multiple recipients viaINTENT. I tried the following to do it:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", etmessage.getText().toString());
intent.setData(Uri.parse("smsto:" + returnedItems));
intent.setType("vnd.android-dir/mms-sms");
mcontext.startActivity(intent);
Where returnedItems is of Contact Numbers
But the problem is that my recipients numbers are not setting on TO section on SMS INTENT where TEXT is displayed on TEXT section.
Make sure that the numbers are seperated by ; .
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:1234456;234567"));
smsIntent.putExtra("sms_body", etmessage.getText().toString());
startActivity(smsIntent);
always works for me!
Did you tried below ?
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999;888888"));
I also found out ";" is not working in Samsung device. You have to add "," instead of ";" for samsungs devices.
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999,888888"));
Also check this answer
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:" + pointsList));
smsIntent.putExtra("sms_body", "Hi Friends & Families, My Location is feeling unsafe in this location");
startActivity(smsIntent);
pointsList is something like ArrayList, for example [8777675673,8566463454,7776666664].
It is working fine.
I have solved this by the following way.
Intent intent = new Intent(Intent.ACTION_SEND);
String numbers = "1234567890;9876543210;453678920"
intent.putExtra("address", numbers);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_image)));
The numbers are separated by semi-colon (;). I read in some mobile phones the numbers need to separated by comma (,).
Hope this will help.

How to attach a xml file to a SMS/MMS message using the Android API

I have a custom file type (MIME_TYPE), basically xml, that I'd like to enable users to send to each other. Implementing the email send feature with the xml file as an attachment was straight forward but I'm kinda stuck on the SMS/MMS send feature. Anyone have any guidance?
final Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mms://"));
intent.setType("text/plain");
intent.putExtra("address", "2125551212");
String url = "content://myFile.txt";
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
intent.putExtra("sms_body", "some text goes here");
startActivityForResult(Intent.createChooser(intent, "mms-sms:"), SENT_TEXT);
the intent.putExtra(Intent.EXTRA_STREAM... doesn't seem to work, I get an error message:
"UNABLE TO ATTACH. FILE NOT SUPPORTED"
try this its worked with me for Send Photo.
use
Uri.fromFile
instead of
Uri.parse
File f=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/DCIM/Camera/"+img_name);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("", "");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
sendIntent.setType("image/png");
startActivity(sendIntent);

Categories

Resources