how when clicked onclick button whatsapp messages can be sent automatically
public void onclick(){
boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
if (isWhatsappInstalled) {
Uri uri = Uri.parse("smsto:" + "628124291xxxx");
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.putExtra(Intent.EXTRA_TEXT, "hallo");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} else {
Toast.makeText(MainActivity.this, "WhatsApp not Installed",
Toast.LENGTH_SHORT).show();
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goToMarket);
}
}
I don't know if it's the way you want it. I believe it is a way of doing. Try this.
String toNumber = "628124291xxxx";
String url = "https://api.whatsapp.com/send?phone="+ toNumber;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("com.whatsapp"); //com.whatsapp or com.whatsapp.w4b
i.setData(Uri.parse(url));
startActivity(i);
Related
I have tried to send Email through Android Intent by using below code
Intent sendIntent = new Intent();
sendIntent.putExtra(Intent.EXTRA_TEXT, EmailContent);
sendIntent.putExtra(Intent.EXTRA_EMAIL, RecipientName );
sendIntent.putExtra(Intent.EXTRA_SUBJECT , subject );
sendIntent.setType("message/rfc822");
sendIntent.setAction(Intent.ACTION_SEND);
Intent chooser = Intent.createChooser(sendIntent , chooser_title );
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
In the email app the recipient details are not getting update whereas all the other details such as subject, body is getting updated with my input . Could you please suggest what needs to be done to resolve this .
Try to pass the EXTRA_EMAIL as string array.
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Try using this:-
Create String resource for recipients:-
<string-array name="receipients">
<item>mgf#kgf.co</item>
<item>sdf#kgf.co</item>
</string-array>
and use this intent
Intent gmailIntent = new Intent(Intent.ACTION_SEND);
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
gmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, resources.getStringArray(R.array.receipients));
gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EmailContent);
gmailIntent.setType("message/rfc822");
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
final PackageManager pm = context.getApplicationContext().getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(gmailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
gmailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
try {
startActivity(gmailIntent);
} catch (ActivityNotFoundException ex) {
Toast.makeText(context.getApplicationContext(), getString(R.string.you_do_not_have_gmail_installed), Toast.LENGTH_SHORT).show();
}
I try to send text message with whatsapp but this code fails every time.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, txtMessage.getText().toString());
startActivity(shareIntent);
Here is the solution for send the message to whatsapp from our application
public void onClickWhatsApp() {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Also see http://www.whatsapp.com/faq/en/android/28000012
i want open a file with hp ePrint exclusively...but with my code, file is opened with adobe reader...i don't know why....
THANKS IN ADVANCE!
public void viewPDF() {
String path = "/sdcard/droidText/ciccia.pdf";
try {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent=new Intent();
intent.setPackage("com.hp.android.print");
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
startActivity(intent);
}catch(ActivityNotFoundException anfe){
final String appPackageName="com.hp.android.print";
try{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=" +appPackageName)));
}catch(android.content.ActivityNotFoundException anfer){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id=" +appPackageName)));
}
}
}
Intent intent=new Intent();
intent.setPackage("com.hp.android.print")
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
You redeclared the intent object.
I am practising by making an app in which the user can send a WhatsApp message to a particular person .I tried some code snippets which i found on internet but whenever i try to send a WhatsApp msg from an actual device, i am gettig an error "No Application can perform this action".
Here is my code:-
public void sendMessage(View v) {
try
{
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
}
Please help .
You receive no application can perform this action because you should remove i.setType("text/plain"); from your code:
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
Unfortunately as you can see WhatsApp now opens in the conversation activity but there isn't the text you set in the Intent. This is because WhatsApp doesn't support this kind of share. The only supported share with Intent is ACTION_SEND as you can see in the WhatsApp FAQ:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
How to open an url in specifying browser from transparent activity?
I'm using the code:
public void open() {
Log.d("info","start");
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setData(Uri.parse("http://rambler.ru"));
i.setAction("com.android.browser");
ComponentName comp = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
i.setComponent(comp);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(
i);
finish();
}
but it doesn't work.
Browser is already opened
Use below code:
String url= "your url"
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Url));
startActivity(browserIntent);