Filtering ACTION_SEND sharing options - android

I am using the following code to share information from my application.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "share Content" );
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "share subject" );
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share Place via"));
The above code displays some options through which i can share, What i would like to achieve is somehow go through the options and omit some of them.
For Example , in my case, if Facebook app is present on the device, the above code displays it as one of the options. As i already have Facebook android sdk integrated in my application. I want to remove the Facebook option from the sharing options.

I think you should have a look at the PackageManager queryIntentActivities (Intent intent, int flags) methods. This will give you a list of Activities matching your Intentand then you can maybe remove some of them, and present a custom Dialog to the user, where you show just the desired Activities. And after the user chooses an Activity you'll have to explicitly start that Activity.

Related

Show share menu like other apps on my android phone

I have added share action on my app's actionbar and followed these steps:
http://www.codewithasp.net/2016/11/share-action-provider-android-application-actionbar-appcompat-v7.html
This is showing a nice simple looking share menu on my actionbar. But problem is that all other application on my phone have different share menu and all of them are similar.
Here is how my share menu look:
Here is how other apps showing share menu on my device
Instead of creating a drop-down menu with share options, you should just call share intent once you've clicked on share button or menu option. That way the list of possible apps would be shown as on the example you've pasted.
Here is an example of how could you do it.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
sendIntent.setType("text/plain");
getContext().startActivity(sendIntent);
There was one more thing to add in SadClown's answer and I got what I wanted. Actually while calling startActivity instead of just pass your share intent we need to call intent chooser
getContext().startActivity(Intent.createChooser(sendIntent, "Share"));
It is explained here in detail

Share links with my app using "Share via" in Android

I'm trying to set my Android application so that it's available to share links from other apps such as Chrome running on Android.
I have set an Intent Filter on an activity so that my app displays in the "Share via" dialog. That part works fine, but I'm not sure how to actually get the data into my "new post" dialog when it launches.
I read an existing StackOverflow question that suggests using this code:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
startActivity(Intent.createChooser(share, "Share Text"));
I have an existing method for creating posts that looks like this:
public void onNewPostMenuSelected(MenuItem item) {
Intent intent = new Intent(this, CreatePostActivity.class);
startActivity(intent);
}
Should I modify this existing method and, if so, how? Or should I be doing something else? Thanks in advance!
I have set an Intent Filter on an activity so that my app displays in the "Share via" dialog. That part works fine, but I'm not sure how to actually get the data into my "new post" dialog when it launches.
If by "the data", you mean the text that was shared, call getIntent() on your activity and read the EXTRA_TEXT extra for that. In the case of browsers sharing URLs, EXTRA_TEXT should be the URL.

In share option in dialog box, I want to add my custom intent option

I am using this code to share link in android app.
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));
But i want to add cutom intent option in dialoag box.
If i have twitter and facebook app in my phone, then above code give me share option
1) Twitter
2) Facebook
3) Bluetooth(if phn supported)
Also with this I want to add
4) Commnets (on comments click user will go my Comment activity)
I want to make share like this.
Can anyone help. Thanks in advance.
You are creating a chooser. It contains all intents that reply to ACTION_SEND text/plain.
To have your comment activity in that list, you need make an intent-filter in your manifest matching that actions for your comment Activity.
Alternatively (and moreeasily, too), if you don't want your Comment activity to respond to external ACTION_SEND text/plain, you can use the response given to this question : Custom filtering of intent chooser based on installed Android package name : Add a Intent.EXTRA_INITIAL_INTENTS extra to the intent.

Don't display Facebook app in Android Intent

Hi I have the following code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
Now I can choose among a lot of applications: Gmail, Twitter, Facebook, SMS
But I don't want to display the Facebook option. Is this possible?
Or is it possible to add custom code when I click on the Facebook item? Like displaying an alertDialog etc
Try send the url like this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("http://www.google.com"));
intent.putExtra(Intent.EXTRA_TEXT, message);
You can
use the PackageManager to resolve the intent,
get the list of candidate applications,
exclude Facebook from that list
create the activity picker yourself with this updated list
This would be the exact opposite of Android Intent for Twitter application

Get the list of apps capable of handling the SEND intent to display in a View (not a popup dialog)

I'm trying to get the list of all apps installed on a phone capable of handling the SEND intent. I am currently handling this situation by using Intent.createChooser but this is not what I am trying to achieve as I would like to be able to get access to the list of apps to display them in a View in my activity, in a way similar to how the Android stock Gallery app displays them and NOT in a spinner dialog.
Screenshot available here: http://i.stack.imgur.com/0dQmo.jpg
Any help would be greatly appreciated.
Call queryIntentActivities() on PackageManager, given an ACTION_SEND Intent configured as you would use with createChooser() (i.e., has the MIME type, Uri, etc.). This will give you a list of all the matches that would appear in the chooser. You can then make use of the user's selection to launch the actual activity.
Here is a sample project that uses this to create a home screen-style launcher.
List<String> packages = new ArrayList<>();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "test");
sendIntent.setType("text/plain");
List<ResolveInfo> resolveInfoList = getPackageManager()
.queryIntentActivities(sendIntent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
packages.add(resolveInfo.activityInfo.packageName);
}

Categories

Resources