Custom chooser android in example
Custom chooser android example is like a dialog to show the list of application depends on the your intent.Here,i have written the simple steps to create the simple custom chooser ,Follow the simple steps to do this.
1)Create Intent to perform share or send operation,
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)Create AlertDialog to set the Application in the alertdialog,
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)Get the list of application related to the particular intent using the ResolveInfo,
List<ResolveInfo> launchables=pm.queryIntentActivities(email, 0);
Collections.sort(launchables,newResolveInfo.DisplayNameComparator(pm));
|
4)Set the list of application to the custom listview.
adapter=new AppAdapter(pm, launchables); lv.setAdapter(adapter); |
5)Finally,lanch the particular application when choose the application from the list of application in listview,
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);
|
No comments:
Post a Comment