I don't want to send emails to other users. I only want to open the launching activity of Email. I have tried it through different ways but every time send email(compose) is opening. But i want to open Email app only nothing else(Sent, outbox, spam, Trash etc).
My code is below
Intent intent = new Intent(Intent.ACTION_SENDTO)
.setData(Uri.parse("mailto:"));
//check if the target app is available or not
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Again, This code opens the send email to(compose) option. But i want to open Email app only nothing else(Sent, outbox, spam, Trash etc).
Use this code to open default Mail Application :
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
this.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(Dashboard.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
Related
My app consits of a web view and has the option to register as handler for links to https://example.com/news.
I have an 'Open in Browser' button that should open the current url in an external browser.
If my app is set as default handler for links to https://example.com/news, then the 'Open in Browser' button does not offer the option to open the url with a browser. Instead my app automaticalls opens the url.
I have seen that it's possible force an app to open urls in chorme, however I want a more general solution that works even if chorme is disabled/not installed. My question is then, how to open the url using any or the default browser?
The code for the 'Open in Browser' button:
if (url != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Your implementation looks good to me and you can use it whether chrome is installed or not but you need to check if it is resolvable or not:
if (url != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
If you want to show list of browsers to user to choose from you can use:
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If your targetSdk is 30 or above take a look at this document too:
https://developer.android.com/training/package-visibility/use-cases
I use this codes to send user to another applications. I wan't the user get send to playstore if the application not exist on he's phone. I was searching for examples but i didn't find anything.
// Launch My App one after clicking the button1
public void launchAppOne(View view) {
Intent launchAppOne= getPackageManager().getLaunchIntentForPackage("com.app.android.myapp1");
startActivity(launchAppOne);
}
// Launch My A after clicking the button2
public void launchAppTwo(View view) {
Intent launchAppTwo = getPackageManager().getLaunchIntentForPackage("com.app.android.myapp2");
startActivity(launchAppTwo);
}
You can use this code. It tries to launch the app and if it doesn't exist, the playstore page for the app is opened.
String packageName = "org.mozilla.firefox";
Intent intent= getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null){
startActivity(intent);
}else{
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
}catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}
}
I'm trying to make this program that when the user clicks a button, a message is sent to a whatsapp number
Here is the code in the onClick method
Uri uri = Uri.parse("smsto:" + "xxxxxxxxxx"); //xxx.. is the mobile number
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, "Check");
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
It shows that there are no apps that can perform this action. Why?
I removed
i.setType("text/plain");
And it works. But the text "Check" is not sent. How to do that if this is not the way.
Your format is slightly different from the example given on the WhatsApp FAQ, so I would modify to match.
From this page:
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Try this code to send ON whatsapp
public void SendWhatsapp(View view) {
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();
}
}
I have an EditText, and a Button. The ET is for adding an email address, and the button is for sending the email. I'm trying to accomplish this without any more steps (aka don't want a chooser). Can someone point me in the right direction please, it seems like such a simple thing to do, but every time I try to do this without a chooser, I get an exception.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"user#email.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "some text");
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(FinalAction.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Im trying to start a new activity AFTER the email is sent
I use the following to invoke the default email client
this.startActivity(Intent
.createChooser(emailIntent, "Send mail..."));
This works fine and starts the email app when you send the message it reurns you to the activity it starts from
I want to then start a new activity( the main Screen) and then close the previous one
I inserted the following
Intent myIntent = new Intent(view.getContext(), Activity1.class);
startActivityForResult(myIntent, 0);
finish();
This works but the email screen is hidden behind the new activity and i have to quit the app to send the email
is there a way of starting the activity after the email is sent?
Im using gmail as the client
Any help appreciated
Mark
Unfortunately I didn't find any info that when you start email client with starActivityForResult() it returns with some result code whether user send email or cancel that action. Gmail sent activity is started within your activity stack so you end up starting two activities, gmail app as second.
Hope this will help you
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL,new String[] { "tony#mail.com"});
email.putExtra(Intent.EXTRA_SUBJECT,"Test");
email.putExtra(Intent.EXTRA_TEXT,"sent a message using for testing ");
email.setType("message/rfc822");
startActivityForResult(Intent.createChooser(email, "Choose an Email client:"),
1);
You need onActivityResult method like below
protected void onActivityResult(int requestCode, int
resultCode, Intent data) {
if(requestCode == MY_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
} else {
Intent ingoHome = new Intent(current.this,
newclass.class);
startActivity(ingoHome);
}
}
finish();
}