Bennett Von Bennett
Bennett Von Bennett

Reputation: 307

android - manipulating the 'share' menu

first off - let me just say that I am NOT asking how to implement a share button in my app or anything like that. I know all about using Intents and Intent Filters etc etc.

what I AM asking about is this: is there any way to get access to the "Share" menu itself? in other words, I'd love to build an app that filters out some of the services I never use but that I don't want to delete from my phone completely.

I tried looking it up in the Android API, but only found info on getting your app to show up in the menu or putting a 'Share' button in your app etc.

Being that I'm still somewhat of a novice programmer, I'm also wondering if there's some way for me to sniff out the API objects that are being created/used when the 'Share' menu is built/displayed? Seems like I could do it in a Debugger session, but I'm not sure how.

Thank you in advance. b

Upvotes: 0

Views: 223

Answers (1)

avepr
avepr

Reputation: 1896

Well, there are two ways to go around Share menu. First one is to use

startActivity(Intent.createChooser(Intent, CharSequence) 

But in this case, I am not sure how to obtain an access to the created share menu, coz it is a separate activity. However, if you wish to have a control over the list of share items being displayed for your app, there is another way to approach your share menu item implementation. Take a look at this code snippet:

//Prepare an intent to filter the activities you need
//Add a List<YourItemType> where you going to store the share-items
List<YourItemType> myShareList = new List<YourItemType>;

PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
int numActivities = activities.size();

for (int i = 0; i != numActivities; ++i) {
    final ResolveInfo info = activities.get(i);
    String label = info.loadLabel(packageManager).toString();

    //now you can check label or some other info and decide whether to add the item
    //into your own list of share items

    //Every item in your list should have a runnable which will execute
    // proper share-action (Activity)
  myShareList.add(new YourItemType(label, info.loadIcon(packageManager), new Runnable() 
     {
       public void run() {
           startResolvedActivity(intent, info);
       }
 }));

}

This code snippet shows how to get a list of the activities which are able to process share request. What you need to do next is to show your own UI. It is up to you what you are going to choose.

Upvotes: 1

Related Questions