1)创建Intent以执行共享或发送操作,
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"velmurugan@androidtoppers.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "Hi");
email.putExtra(Intent.EXTRA_TEXT, "Hi,This is Test");
email.setType("text/plain");
2)创建AlertDialog,在alertdialog中设置Application,
final Dialog dialog = new Dialog(Custom_chooser.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
WMLP.gravity = Gravity.CENTER;
dialog.getWindow().setAttributes(WMLP);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.about_dialog);
dialog.show();
3) 使用 ResolveInfo 获取与特定意图相关的应用程序列表
List<ResolveInfo> launchables=pm.queryIntentActivities(email, 0);
Collections.sort(launchables,newResolveInfo.DisplayNameComparator(pm));
4))将应用程序列表设置为自定义列表视图。
adapter=new AppAdapter(pm, launchables);
lv.setAdapter(adapter);
5)最后,从列表视图中的应用程序列表中选择应用程序时,启动特定应用程序,
ResolveInfo launchable=adapter.getItem(position);
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,
activity.name);
email.addCategory(Intent.CATEGORY_LAUNCHER);
email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
email.setComponent(name);
startActivity(email);
有关更多信息,请参阅此链接:http: //velmuruganandroidcoding.blogspot.in/2014/01/custom-chooser-android-in-example.html