Android Custom Intent Chooser with Example

Android custom Intent chooser is like a dialog to show the list of application depends on your intent. below, I have written the simple steps to create the simple custom chooser in Android. Please follow the simple steps to create Android custom Intent chooser.

Android custom Intent chooser downloadAndroid custom Intent chooser github

1)Create Intent to perform share or send operation

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
email.putExtra(Intent.EXTRA_SUBJECT, "Hi");
email.putExtra(Intent.EXTRA_TEXT, "Hi,This is Test");
email.setType("text/plain");

shimmer effect For Android Recyclerview Example

Glide – Image loading framework for Android with Example [Part 1]


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);

Glide – Image loading framework for Android

EventBus in Android


5)Finally, launch the particular application when choosing the application from the list of application in the 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);

Screenshot:

create custom choose

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top