I need to send app invitation message from my app to friends via whatsapp,facebook,hike,... with the message and playstore link.I have seen this kind of invitations in other apps like hike,whatscall,... like the
attached image
I want to send exactly the same kind of message with the playstore link and app logo for my app also and it should be shared using all the available sharing option in users mobile.In my application i have included a inform friends menu and on clicking on that this function should work.I have seen firebase app invite examples but it needs google-services.json and i think it will only send text message from users email,I am not sure about that.
Sending text msg or image or both via app can be done using Action_send intent. The following code should work for your requirement.
void shareImageWithText(){
Uri contentUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher");
StringBuilder msg = new StringBuilder();
msg.append("Hey, Download this awesome app!");
msg.append("\n");
msg.append("https://play.google.com/store/apps/details?id=Your_Package_Name"); //example :com.package.name
if (contentUri != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
shareIntent.setType("*/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
try {
startActivity(Intent.createChooser(shareIntent, "Share via"));
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "No App Available", Toast.LENGTH_SHORT).show();
}
}
}
Related
I'm developing an application that can send message through whatsapp. I have implemented it by following this answer but it only works for contacts that on my contact list. It keeps error when i try to send message to contacts that are not in my contact list although the user already registered on whatsapp using that number (contact). Here is the message from whatsapp:
here is my code:
try {
Uri uri = Uri.parse("smsto: " + smsNumber);
//Timber.e("smsNumber %s", uri.toString());
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
} catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
is there any solutions ?
you can send via WhatsApp API even if he is not in your contact
String whatsappUrl = String.format("https://api.whatsapp.com/send?phone=%s&text%s",PhoneNumber,msg);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(whatsappUrl));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
p_context.startActivity(browserIntent);
I am building an android app. My app needs to send the customer's(who is giving purchase order) phone number to a specific mobile number via either whatsapp or sms. But I also want to restrict all other apps from my share via list other than these two.
I know how to use sharing Intent but don't know how to restrict all other apps from that drop down list.
To restric all the other app you need to provide the package name of the app you wanted to open e.g.
Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.whatsapp");
this is the package name for whats app.
you can easily get the packege name from setting->apps-> your App
For more information click here
Try this for whatsapp
public void shareViaWhatsapp() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
For SMS
public void sendSMS(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity()); // Need to change the build to API 19
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else // For early versions, do what worked for you before.
{
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("sms_body","This is my text to send.");
startActivity(smsIntent);
}
}
Above answer is sufficient for your question.But for other coders this may help :)
For whatsapp :
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, textToSend);//
startActivity(Intent.createChooser(waIntent, "Share with"));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
} catch (Exception e) {
Toast.makeText(ShareActivity.this,"Could not launch WhatsApp.",Toast.LENGTH_SHORT).show();
}
For Message :
try {
Intent sendIntentmsg = new Intent(Intent.ACTION_VIEW);
sendIntentmsg.setData(Uri.parse("sms:"));
sendIntentmsg.putExtra("sms_body", textToSend);
startActivity(sendIntentmsg);
} catch (Exception e) {
Toast.makeText(ShareActivity.this,"Could not launch Messaging App now.",Toast.LENGTH_SHORT).show();
}
I want to share my location to a Whatsapp contact.
I don't know what is the mimeType that I have to use. This is the code I'm usign to share:
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setPackage("com.whatsapp");
waIntent.setType("text/plain");
waIntent.putExtra(Intent.EXTRA_TEXT, "geo:23.1097,-82.4094");
startActivity(waIntent);
But this only send a plain text, not a location like Whatsapp does. Any idea??
Note: I donot have (and dont want to have) Whatsapp but maybe my findings help you
since "geo:..." is a uri (defined here) you should wrap it into a Uri and send it as data.
This code works with other location aware android apps like GoogleMaps
String uriString = "geo:23.1097,-82.4094";
Intent waIntent = new Intent();
// waIntent.setPackage("com.whatsapp");
Uri uri = Uri.parse(uriString);
waIntent.setData(uri); // finds several apps on my phone including googleMaps
// waIntent.setDataAndType(uri, "*/*"); // does not work on my phone: nothing found
Toast.makeText(this, appName + "Starting " + uriString, Toast.LENGTH_SHORT).show();
try {
this.startActivity(Intent.createChooser(waIntent,"Choose app to show location"));
} catch (Exception e) {
Toast.makeText(this, appName + e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
You can check if whatsapp understand this, too
I am trying to send a photo through MMS message, I am using the following known snippet
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, "This is an MMS message");
String sendfilepath = "file://" + sendfile.toString() + ".jpg";
i.putExtra(Intent.EXTRA_STREAM,Uri.parse(sendfilepath)) ;
i.setType("image/jpeg");
It works with my Sony device. The pop up menu shows the messaging app along with other apps.
But with HTC it does not show the Messaging app. It shows Bluetooth, Facebook, Mail, etc. How can I make it show the Messaging app in the "Complete action using" list
You can use this technique to check for HTC sense device and react appropriately to send the proper "version" of the intent.
Uri uri = Uri.fromFile(imgFile);
//HTC Sense intent
Intent sendIntent = new Intent("android.intent.action.SEND_MSG");
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/"+type);
List<ResolveInfo> resolves = getPackageManager().queryIntentActivities(sendIntent,PackageManager.MATCH_DEFAULT_ONLY);
if (resolves.size() > 0) {
// This branch is followed only for HTC
startActivity(sendIntent);
} else {
// Else launch the non-HTC sense Intent
sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/"+type);
startActivity(Intent.createChooser(sendIntent,"Send"));
}
I'm developing an android application and I want to can share in a tweet a picture. I search for tutorials and all of them have to authentificate the user before can post a tweet. Is there any way to use the account that's stored on your phone instead of authenticating the user again?
I don't want to have a share button, I want that like in iPhone can post a tweet.
If anyone know of other toturial that works and it's better please tell me, I don't want a share button, only I want to tweet.
Thanks
Use shareIntent, as described here:
public void shareTwitter() {
String message = "Your message to post";
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("com.twitter.android","com.twitter.android.PostActivity");
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(sharingIntent);
} catch (Exception e) {
Log.e("In Exception", "Comes here");
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, theObject.getName());
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://mobile.twitter.com/"));
startActivity(i);
}
}