Android Custom intent selection

I wonder if there is a way to choose behavior using the Intent.createChooser method? For example, I have an image that I would like to send by email if it is selected (first option). And according to the second option, I would like to send sms with a link to this image (Why do I need complex actions - upload the image to the section, upload the download link that I would like to find in sms and paste in sms )

Could you come up with any suggestion, what should I do to complete the second task?

I believe I can send an email with an image with something like this:

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("application/image"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{textMail}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Some Subj"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Some Extra Text"); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileUri)); startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

UPD: I realized that I really need to intercept the user's click if sms was selected in the choice of intentions. So the question is, how can this be done?

+7
android android-intent
source share
3 answers

1) Create an intention to perform a sharing or sending 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 an AlertDialog to install the application in 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 a list of applications related to a specific intention using ResolveInfo

 List<ResolveInfo> launchables=pm.queryIntentActivities(email, 0); Collections.sort(launchables,newResolveInfo.DisplayNameComparator(pm)); 

4)) Set the list of applications to a custom listview.

 adapter=new AppAdapter(pm, launchables); lv.setAdapter(adapter); 

5) Finally, launch a specific application when you select an application from the list of applications in the list,

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

For more details see the link: http://velmuruganandroidcoding.blogspot.in/2014/01/custom-chooser-android-in-example.html

+10
source share

It seems to me that it cannot be executed exactly as I wanted.

A possible way is to create a custom selection of applications using queryIntentActivities () in the PackageManager class. Useful post: Custom intent filtering based on installed Android package name

Another possible way is to create a custom popup - http://developer.android.com/guide/topics/ui/menus.html#PopupMenu
or floating context menu -
http://developer.android.com/guide/topics/ui/menus.html#FloatingContextMenu

It seems that in fact the desired client was just an ordinary Dialog . Something like that:

 public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("E-mail / MMS").setItems(R.array.send_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' argument contains the index position // of the selected item } }); return builder.create(); } 
+1
source share

In addition to the selected answer .
You can also add a control for Facebook, since Facebook does not work with the seller:

 if (activity.applicationInfo.packageName.toLowerCase().contains("facebook")) { //Share on Facebook ShareLinkContent content = new ShareLinkContent.Builder(). setContentUrl(Uri.parse(mLink)). setImageUrl(Uri.parse(mImageURL)). setContentTitle(mTitle). setContentDescription(mDescription) .build(); com.facebook.share.widget.ShareDialog.show(mActivity, content); } else { //Share on selected application ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); mActivity.startActivity(shareIntent); } 
0
source share

All Articles