StartActivityForResults always returns RESULT_CANCELLED for Intent.ACTION_SEND

When a pop-up message appears, I shared the content on WhatsApp successfully, but still returns RESULT_CANCELLED. Same result when I send an email using Gmail.

Call ACTION_SEND with startActivityForResult always returns CANCELLED

 Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE, "Taxeeta, Cab Around The Curb"); sharingIntent .putExtra( android.content.Intent.EXTRA_TEXT, "Hiring a cab no longer needs you to wait on call centers, or pay a" + " convenience (yeah right!!) charge. Taxeeta connects you" + " to drivers directly, for a quick book experience. With Taxeeta" + " you can take matters in your own hands (literally). To download" + " the app for your phone visit http://www.taxeeta.com"); startActivityForResult(Intent.createChooser(sharingIntent, "Share and earn a extra Priviledge"), 111); 

ActivityForResult Code

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 111) { if (resultCode == RESULT_OK) { Toast.makeText(this, "Ok DUDE", Toast.LENGTH_LONG).show(); } else if (resultCode == RESULT_CANCELED) { Toast.makeText(this, "Oversmart Eh!!", Toast.LENGTH_LONG).show(); } } } 
+7
source share
2 answers

startActivityForResult() only works with actions that should be called this way. If the action you invoke does not explicitly return a result, you will get the default result RESULT_CANCELED. Obviously, ACTION_SEND not intended to be called this way. The documentation for ACTION_SEND indicates that it is not generating a result (i.e., it is not generating any result).

See the documentation for Activity.startActivityForResult() :

Note that this method should only be used with Intent protocols, which return the result. In other protocols (such as ACTION_MAIN or ACTION_VIEW), you may not get the result when you expect. For example, if the action that you run uses singleTask, it will not run in your task, and you will immediately receive the cancellation result.

+27
source

I have the same problem, and I think that the result will always be "canceled", because even if the letter is sent or not, the activity will be killed.

0
source

All Articles