I am trying to build a background service in which I can send message from my whatsapp to the other user's whatsapp.
I've tried this code
PackageManager packageManager = getApplicationContext().getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone=" + "+91 7*********" + "&text=" + URLEncoder.encode("hhellow User", "UTF-8");
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
startActivity(i);
}
} catch (Exception e) {
e.printStackTrace();
}
But it is again redirecting me to whatsapp and ask me to send the message. I don't want to open my whatsapp screen, message should directly be send to the user (in background).
I know this question is already asked but I didn't get my answer all are redirecting me to whatsApp.
As per the WhatsApp FAQ there are only two ways to send text
Using Url
Using Intent
In both cases users have to click send button explicitly to send the message.
So as of now it is not possible to send message directly using any background service without clicking send button from WhatsApp itself.
Related
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();
}
}
}
I've developed an ionic 3 app. I am unable to open whatsapp from my app with a specific contact in ionic 3. i don't want to send or share any thing but only wants to open whatsapp in android & iOS from my app with a specific contact. Is there any way to open whatsapp?
Till now i have implemented as below which is not working
window.open(`whatsapp:${+911234567890}`, '_system');
Any help much appreciate.
See it:
http://phonegap-plugins.com/plugins/ranjitpandit/whatsapp-phonegap-plugin
cordova.plugins.Whatsapp.send("yourNumber", sucessoCallback, errorCallback);
I am Using this:
String phone = "+8801510101010";
PackageManager packageManager = MainActivity.this.getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone="+ phone;
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
MainActivity.this.startActivity(i);
}
} catch (Exception e){
e.printStackTrace();
}
I have custom image keyboard app from which i am sharing image to any social media chatting application.
Now, As WhatsApp not supporting Commit content API to share image directly, I am using Intent to share image to WhatsApp.
Code is as below :
private void shareViaIntent(Context mContext, int iconPosition) {
try {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType(getResources().getString(R.string.strIntentType));
Uri uri = null;
if (mStrPackageName.equals(getResources().getString(R.string.strWhatsAppPackage))) {
//inorder to send images with white background to WhatsApp.
uri = FileProvider.getUriForFile(mContext, getResources().getString(R.string.strFileProviderPackage), mArray_wapp_Icons[iconPosition]);
} else {
uri = FileProvider.getUriForFile(mContext, getResources().getString(R.string.strFileProviderPackage), mArray_Icons[iconPosition]);
}
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setPackage(mStrPackageName);
startActivity(shareIntent);
} catch (RuntimeException runTimeException) {
runTimeException.printStackTrace();
} catch (Exception exception) {
exception.printStackTrace();
}
}
Now, The issue is that When I am in open chat window for specific person. Means In WhatsApp app, If i am chatting with person named "xyz", then image is not sending directly to person named "xyz". It opens "SEND TO" window in WhatsApp, where i can select multiple contact to share image.
.
But, I just have to share selected image to that particualr "xyz" person.
So, Is there any changes needed in Intent as I have coded ?
Please, Guide.
I want to send a picture preview in my mail Intent.
I dont want to attach it, i just want it to be shown.
This is my intent:
String textToSend = getString(R.string.mailHi)+"<br><br>"+getString(R.string.mailText)+getTextToSendViaMail();
Uri pngUri = null;
File currentShopImage = new File(Environment.getExternalStorageDirectory().toString()+"/OpenGuide/"+Integer.toString(keyId)+"_1_normal.pn_");
if(currentShopImage.exists()){
File pngFile = new File(currentShopImage.toString());
pngUri = Uri.fromFile(pngFile);
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
//i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailCim });
i.putExtra(Intent.EXTRA_SUBJECT, "OpenGuide");
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(textToSend));
if(pngUri!= null)
i.putExtra(Intent.EXTRA_STREAM, pngUri);
try {
startActivity(Intent.createChooser(i, getString(R.string.SendMail)));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ShopActivity.this, getString(R.string.MailClientNotFound), Toast.LENGTH_SHORT).show();
}
How can i achive such a thing ?
As far as I understood your problem, you want to place the image inside the mail with other text. In the words of Email protocol it's called an INLINE Attachment.
You would not be able to do this with intents as none of the email clients installed on the device supports creating html messages.
If it's really a core part of your app, you should consider a third party api to do this. One of the such library is JavaMail. You would be able to send html messages through this library but will take some time in setting up.
Here's a link that may give you some hint, how it's done.
Then you need to send a HTML generated email afaik.
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);
}
}