Java tutorial
//package com.java2s; /** * @copyright Copyright (C) 2011 Asela Leelaratne * @license GNU/GPL Version 3 * * This Application is released to the public under the GNU General Public License. * * GNU/GPL V3 Extract. * 15. Disclaimer of Warranty. * THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES * PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE * PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL * NECESSARY SERVICING, REPAIR OR CORRECTION. */ import java.util.ArrayList; import java.util.List; import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Parcelable; public class Main { /** * Intent chooser is customized to remove unwanted apps. * 1. FaceBook has bug where only links can be shared. * 2. Cannot share this type of content via Google Docs and Skype. */ public static void ShareResult(Context mContext, String mResult, String mTitle) { List<Intent> targetedShareIntents = new ArrayList<Intent>(); Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); List<ResolveInfo> resInfo = mContext.getPackageManager().queryIntentActivities(shareIntent, 0); if (!resInfo.isEmpty()) { for (ResolveInfo resolveInfo : resInfo) { String packageName = resolveInfo.activityInfo.packageName; Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND); targetedShareIntent.setType("text/plain"); targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle); targetedShareIntent.putExtra(android.content.Intent.EXTRA_TITLE, mTitle); targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mResult); if (!packageName.toLowerCase().contains("com.facebook.katana") && !packageName.toLowerCase().contains("com.google.android.apps.docs") && !packageName.toLowerCase().contains("com.skype.raider")) { targetedShareIntent.setPackage(packageName); targetedShareIntents.add(targetedShareIntent); } } Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Send your result"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); mContext.startActivity(chooserIntent); } return; } }