+ mIntent = getArguments().getParcelable(ARG_INTENT);
+ String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
+ List<String> packagesToExcludeList = Arrays.asList(packagesToExclude != null ? packagesToExclude : new String[0]);
+ mFile = getArguments().getParcelable(ARG_FILE_TO_SHARE);
+
+ PackageManager pm= getSherlockActivity().getPackageManager();
+ List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
+ Iterator<ResolveInfo> it = activities.iterator();
+ ResolveInfo resolveInfo;
+ while (it.hasNext()) {
+ resolveInfo = it.next();
+ if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
+ it.remove();
+ }
+ }
+ Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
+ mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
+
+ boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);
+
+ if (sendAction) {
+
+ return new AlertDialog.Builder(getSherlockActivity())
+ .setTitle(R.string.activity_chooser_title)
+ .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Add the information of the chosen activity to the intent to send
+ ResolveInfo chosen = mAdapter.getItem(which);
+ ActivityInfo actInfo = chosen.activityInfo;
+ ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
+ mIntent.setComponent(name);
+
+ // Send the file
+ ((FileActivity)getSherlockActivity()).startActivity(mIntent);
+
+ }
+ })
+ .create();
+ } else {
+ return new AlertDialog.Builder(getSherlockActivity())
+ .setTitle(R.string.activity_chooser_send_file_title)
+ .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Add the information of the chosen activity to the intent to send
+ ResolveInfo chosen = mAdapter.getItem(which);
+ ActivityInfo actInfo = chosen.activityInfo;
+ ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
+ mIntent.setComponent(name);
+
+ // Create a new share resource
+ FileOperationsHelper foh = new FileOperationsHelper();
+ foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity());
+ }
+ })
+ .create();
+ }
+ }
+
+
+ class ActivityAdapter extends ArrayAdapter<ResolveInfo> {
+
+ private PackageManager mPackageManager;
+
+ ActivityAdapter(Context context, PackageManager pm, List<ResolveInfo> apps) {
+ super(context, R.layout.activity_row, apps);
+ this.mPackageManager = pm;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = newView(parent);
+ }
+ bindView(position, convertView);
+ return convertView;
+ }