I've gone through plenty of WhatsApp posts here in StackOverflow.
Like these:
Is it legal to use WhatsAPI?
Android Whatsapp/Chat Examples
Sending message through WhatsApp
My question is this. I manage to send a message from my app to WhatsApp for someone that is in my contact list.
However, I want to send a message (NOT SPAM!) to someone who is not on my Contact List through WhatsApp, and I'm unable to do so with the given solutions.
How is it possible?
By the way, how is it possible to fill the body of a WhatsApp text field with a pre-defined message, so the user can edit or send immediately?
"sms_body", or Intent.EXTRA_TEXT doesn't seem to work...
public void shareWhatsApp(String whatsappid) {
try {
Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?",
new String[] { whatsappid }, null);
c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.putExtra(Intent.EXTRA_TEXT, "Hello!");
startActivity(i);
c.close();
} catch (Exception e) {
Toast.makeText(this, "Install WhatsApp First", Toast.LENGTH_LONG).show();;
e.printStackTrace();
}
}
You should only access Call Log or SMS permissions when your app falls within permitted uses and only to enable your app’s critical core functionality.
Core functionality is defined as the main purpose of the app. This may comprise of a set of core features, which must all be prominently documented and promoted in the app's description. Without the core feature(s), the app is "broken" or rendered unusable.
link -https://support.google.com/googleplay/android-developer/answer/9047303?source=post_page-----9b8226de7827----------------------
You will need some EXTRAS to put into the Intent.
Also you may use the phone number instead of the id.
See this solution here
I answered this question recently and it works very well, please search my answer here:
Send text to specific contact programmatically (whatsapp)
It really works to send a specific message to a specific contact in WhatsApp from your own Android app,
Enjoy! :)
Related
This is a silly and not important subject, but nothing to lose on asking.
My app has a "Share App" feature in main menu which sends a promotion email with text and a set of app screenshots, and in the end it calls the following method:
public static void shareFile(ArrayList<Uri> uris, String fileType)
{
try{
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType(fileType);
String strSubject = TMLocale.getStringResourceByName("mainmenu_sharethisapp_subject");
share.putExtra(Intent.EXTRA_SUBJECT, strSubject);
share.putExtra(Intent.EXTRA_TEXT, TMLocale.getStringResourceByName("mainmenu_sharethisapp_recommendtext"));
share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
activity.get().startActivity(Intent.createChooser(share, TMLocale.getStringResourceByName("mainmenu_sharethisapp_shareapptitle")));
}
catch(Exception ex){
Toast.makeText(activity.get(), String.valueOf(ex.getMessage()),Toast.LENGTH_LONG).show();
}
}
This is working great, but what you receive -for example by mail- is an unordered set of attachments, I mean, the attachments order does not correspond to the ArrayList<Uri> order.
I'd like the attachments to be ordered as the ArrayList is, so who receives the email can see how the app works following the attachments (from Gmail -for example- and without downloading them) in a "readable"/"understandable" way, like following the same work sequence a user would follow using the app.
I have made several tests just to confirm attachments always arrive not only unordered, but in a different -maybe random- order.
Is it possible to sort the attachments?
I'd like the attachments to be ordered as the ArrayList is
Then use exactly one attachment, where you attach a document that puts your images in the desired order.
Otherwise... your code is starting an ACTION_SEND_MULTIPLE activity. There are likely thousands of these in the Play Store and elsewhere. How any of them handle your extras is up to their developers, not you or me.
I need to be able to check if the user has sent the text I set in my code;
Intent messageIntent = new Intent(Intent.ACTION_SEND)
messageIntent.putExtra(Intent.EXTRA_TEXT, "Text I want to send");
or has changed the prefixed text (on the SMS client app, email client app, or the app that gets launched by the intent) before sending it.
I need to know this because sharing my game link will give a reward to the user, so I need to check if that link is correctly shared.
I would appreciate any answer that could help.
Thanks.
ACTION_SEND isn't documented to return a result. So starting the intent with startActivityForResult() will return the default result: RESULT_CANCELED. That is, unless the receiving app has implemented support for returning a result; which is highly unlikely because it's not part of the documented behavior.
In summary, what you want to do is not possible with any of the common Intents.
You can try this...
String message = "Your Message";
intent.putExtra("IDENTIFIER", message);
And where you are going to receive the message...
String messageReceived = getIntent().getExtras().get("IDENTIFIER").toString();
I have a scenario in mind and I don't know if it's possible:
Open the SMS interface from my app.(I can make this part)
Use the interface to write the message and search the contact(s).
When send button is pressed I want to store the information in my app and send it later.(I don't know if this is possible, if it is please give me some help)
Sounds possible to me. You probably want the SMSManager to send a text... source
// Simplified...
String phoneNo = "8675309";
String sms = "Beni, I've got your number";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
} catch (Exception e) {
e.printStackTrace();
}
Regarding searching the contacts and sending the text at a later time, it would be helpful if you could provide more specifics.
How will your app search the contacts? Display a full list for them to pick from? Allow them to enter text to match against the contact's name?
When you say "Send it later", what are your constraints for later?
For example, you could simply bring up their phone's contact viewer, and let them choose...
When I am Using this code to send mms to specific user it shows me popup to send it via gmail,whatsapp,gtalk,message and etc. But in my case I just want to send that image as an mms to specific number that i will define in address field whithout showing any popup can any body tell me How to do this ? I googled for this and find lot of stuff on it.
Here is my code*strong text*
public void sendData(int num){
String fileString = "..."; //put the location of the file here
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "text");
mmsIntent.putExtra("address", num);
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileString)));
msIntent.setType("image/jpeg");
startActivity(Intent.createChooser(mmsIntent, "Send"));
}
Using an intent (like you did) is the preferred way because it's easy to implement and let the user choose his favorite app for the task of sending the MMS.
That being said you can still implement yourself the operation and send the MMS programmatically from your app by crafting and sending the appropriate HTTP request.
The following answer will provide you all the information you need: How to send image via MMS in Android?
Thanks in advance for your help.
I am developing an Android App that, as part of its core functionality, needs to send emails between users (peer-to-peer emails, not spam). These emails need to contain a link that will open the Android App upon a user-click
The problem I am having is: when I send these emails to gmail acounts, links appear as normal text rather than as links.
Here is my code
private void sendEmail(String recepientName, String recipientEmail) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { recipientEmail };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Title");
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(
"<!DOCTYPE html><html><body>" +
"<br>Dear " + recepientName + ",<br>" +
"Please <font>click here</font></body></html>"));
startActivityForResult(emailIntent, EMAIL_REQUEST);
}
What should I do to make these link work in received emailsin gmail ?
Again Thanks
What I discovered was that somehow (probably with great talent) I got into Google's black list.
this means that Google stripped the link out of my code and the users saw it as regular text
HERE IS THE REASONING:
My link looked like this: myAppName://parameter1/parameter2/Parameter3
The prefix ("myAppName://") allows Android to identify my App and launch it as you click on the link.
HOWEVER:
When this link was sent to a gmail account, Google's servers were able to identify that this was an invalid link (pretty cool that they check that ha!!) and they stripped the link out.
The solution was to use a real URL for App identification and Launch:
Something like: http://myhost.com/parameter1/parameter2/Parameter3
Hope that helps
android:scheme="http" and the appropriate android:host