Successful Share Intent for Android

How to confirm Android Share Intent is successful or complete

Personally, I was about to say "use startActivityForResult()" and check what gets returned. However, as you can read more here, it's not as simple as that. If the intent is cancelled by the user, the same number is returned as if the intent was completed (for most appications).

Ultimately, at the moment for a simpler Share intent in general, you cannot check if it's successful or not.

Successful share intent for android

I don't think there is an assured way to do it.

You could initiate the send using startActivityForResult() and hope that the activity which handles the Intent replies with a RESULT_OK. But you can't rely on it to work always.

Android Share Intent Completed

No, for two reasons:

  1. Just because the user continued past the chooser to some app does not mean that the user "completed the action successfully" (e.g., might have chosen not to actually do anything in the Twitter app once there)

  2. You have no way of finding out whether the user actually continued past the chooser in the first place

You could address the second problem by implementing your own chooser, using PackageManager and queryIntentActivities().

How to get success callback on Intent.ActionSend

After a few more hours of research, I found the solution in the Android developer guides (at https://developer.android.com/training/sharing/send.html).

...if you call Intent.createChooser(), passing it your Intent object, it returns a version of your intent that will always display [a] chooser.

So asynchrony can be achieved by changing the call to:

StartActivityForResult(Intent.CreateChooser(shareIntent, "Share file"), 0)

The OnActivityResult override is executed after the chooser completes. While the resultCode still returns cancelled, the data parameter is null if the user cancelled out of the chooser and otherwise is an intent containing the name of the chooser used (not the name of the target app used). This can be used to determine chooser success by changing the line to

Completed?.Invoke(null, data != null)

Subscribers to the Completed event will be notified after the chooser process is completed, and a follow-up action can be executed.

The downside is that there is no way to determine if the user cancelled out of or completed the target operation with success, but that can be worked around.

Intent Android Sharing

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

while you click on List item you know which application you choose to share your content and and here you can count for that application.

How do I listen/catch success events of social media sharing using Android Share Intent Chooser (ACTION_SEND)?

No, sorry. You don't get any feedback on what the recipient of an ACTION_SEND intent does with it.

Can i confirm app user did share my app link with Intent.ACTION_SEND?

Sorry, that's not possible. You're correct about the reason: there's no return value. It wouldn't be possible to have a sensible return value across all possible methods of sharing—for example, what if they saved it as a draft in their email client to send later?

If you want to confirm that the user actually shared something, you could always use app-specific APIs (e.g., this API for Twitter) that would allow you to share the post from within your app. Of course, don't forget that there's nothing stopping the user from deleting the post immediately after posting it :-)



Related Topics



Leave a reply



Submit