How can I prevent my app from showing specific apps on startActivity() - java

When a user clicks a button in my app, it's supposed to launch an SMS app. To to this, I simply fired an intent.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "+234000000000", null));
intent.putExtra("sms_body", "Hello!"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(intent);
This works perfectly fine! The only problem is that Facebook Messenger is among the list of apps that show up and I don't want that.
How can I filter this list and remove specific apps like Messenger?

Yes, you can restrict your app to open just android default messaging app.
Uri uri = Uri.parse("sms:+444498494984");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
//android sms app package name
intent.setPackage("com.google.android.apps.messaging");
intent.putExtra("sms_body", "message to send");
if (intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}

It is trying to give the user a choice on their favourite SMS app, Don't forget that Facebook Messenger can also manage SMS now that is why it is showing up as a choice. In my experience, Unless the user selects 'always' it can't be avoided. Imagine if the user has other apps to manage SMS we can't force them to use our preferred messaging app.

Related

How to solve android email intent problem?

I am having a problem with android email intent.....i need to open email app so that the user can provide feedback for my app.It doesn't open when i use this..throws an ActivityNotFoundException .....i am using my phone ,not an emulator and my phone has email and gmail apps in it.
Help me solve??
Here is my code:
Intent intent= new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.setType("text/plain");
String[] mail={"someone#gmail.com"};
intent.putExtra(Intent.EXTRA_SUBJECT,"");
intent.putExtra(Intent.EXTRA_TEXT,"");
intent.putExtra(Intent.EXTRA_EMAIL,mail);
startActivity(intent);
Any and all comments are appreciated :)
For your case, what ActivityNotFoundException most likely means that in your phone you don't have any default email app email application installed on your device like Gmail, so when you launch the Intent you receive this error.
You can try to handle that exception like this:
try {
startActivity(Intent.createChooser(i, "Send mail"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}
From the android docs, An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object. This type of intent is called an implicit intent because it does not specify the app component to start, but instead specifies an action and provides some data with which to perform the action.
When you call startActivity() or startActivityForResult() and pass it an implicit intent, the system resolves the intent to an app that can handle the intent and starts its corresponding Activity. If there's more than one app that can handle the intent, the system presents the user with a dialog to pick which app to use.`
So, in your case, the system couldn't find an app to resolve the intent to as #Tamir mentioned.
For more information , look into this Stack Overflow post: Send Email Intent
it works for me :
String[] recipients;
Intent intent = new Intent(Intent.ACTION_SEND);
recipients = new String[]{"someone#gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.setType("text/html");
intent.setPackage("com.google.android.gm");
try {
activity.startActivity(Intent.createChooser(intent, "Send"));
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}

Android Share Link with WhatsApp

I am trying to share link with my android app with this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, share);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
mContext.startActivity(intent);
this is the share Strong :
Check out my link:\n http://my123domain.com/v.php?vid=123456-123456-123456
But when i share it with Whats App the link is not click able,
Any idea Why?
Whatsapp does not allow sending clickable text links to people who do not have you in their contact list. Make sure receiving party have you in their contact list.

Sharing a video via intent to messaging apps like Viber

With this code i want to share an MP4 video to messaging apps like WhatsApp, Viber, Line etc. but only WhatsApp can do it successfully, But for Example if i choose Viber, After selecting recipient nothing happens, Screen flashes and nothing happens. how i can fix it?
Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(String.valueOf(path)));
intent.setDataAndType(Uri.parse(String.valueOf(path)), "video/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(String.valueOf(path)));
context.startActivity(Intent.createChooser(intent, "Share video using"));

How do i redirect the user to Data Usage settings in android?

Like if i want to redirect the user to Location service i have to use
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
Now what shoulb the ACTION_ to let the user go to the data usage settings where he can enable the Mobile Data Traffic?
Are you sure you aren't looking for:
final Intent dataUsage = new Intent(Intent.ACTION_MAIN);
dataUsage.setClassName("com.android.settings",
"com.android.settings.Settings$DataUsageSummaryActivity");
startActivity(dataUsage);
Your title suggests that's what you want, but your comment suggests you wanted the network operator settings.

Sending email through intent without having to press send button

Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)

Categories

Resources