Android Question ActivitySetResult + FileProvider + Bitmap = Failure

drgottjr

Expert
Licensed User
Longtime User
This is a trimmed version of a thread started here:
Perhaps the length of the original post was not appropriate.

I am trying to figure out why it's possible to send a bitmap using StartActivityForResult but not with ActivitySetResult.
2 very simple examples demonstrating the exchange and the exception thrown are attached.

It only occurs when using FileProvider, which - I believe - I am using following the rules. I have tried several variations,
but any attempt using FileProvider in combination with ActivitySetResult fails with the same error (as shown in the attached log).
It is possible, for example, to use a byte array with ActivitySetResult, but Android sets a limit on the length of that array. The
example allows you to toggle between these variations to show how one succeeds and the other fails.
 

Attachments

  • log.txt
    1.9 KB · Views: 45
  • sender.zip
    14.2 KB · Views: 52
  • receiver.zip
    10.4 KB · Views: 45

JohnC

Expert
Licensed User
Longtime User
I had another thought...

I noticed that in the reciever code, right after it sends the "return image" intent to the sender, it does an activity.finish.

Is it possible that doing an activity.finish is closing the app in a way that is preventing it from later "providing" the image to the sender?

In other words, the sender gets the intent because the OS handles sending the receiver generated intent to the sender, but when the sender then tries to retrieve the image, it can't get it because the receiver's "file provider" service is no longer running?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
What are you trying to do?
Basically, he has two apps.

The "Sender" apps sends an image via an intent to the "Reciever" app, and this part works.

But when the "Receiver" app tries to send an image back to the "Sender" using an intent, the sender does properly recieve the intent and the URI part of the intent, but when the Sender tries to retrieve the image from the receivers's file provider using the URI, it fails.
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
just to be clear, sender uses StartActivityForResult, and receiver uses ActivitySetResult. technically, they both work as expected.

Sender uses FileProvider to set up the Uri. Receiver receives the Uri and opens the resource. That works fine.

Receiver uses FileProvider to set up the Uri to return the image. Sender receives the intent and the Uri, BUT the exception is thrown when Sender tries to open the resource. If I return the image as a byte array (without FileProvider), there is no problem. Unfortunately, Android limits the size of the transfer buffer, so if an image is larger than 1MB, you can't use a byte array. And, of course, I can have Receiver send a regular intent to Sender with the Uri; that works. But it means not using StartActivityForResult and ActivitySetResult. If I'm using them legally, why don't they work in this case? What does the exception mean?

I'm not even sure FileProvider is the source of the exception. The last line of the exception output:
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2465)
also appears a number of times in Google searches.

If the 2 examples are run, all will be clear.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
saw that years ago; not what i'm doing. thanks anyway. the simple examples demonstrate clearly.
 
Upvote 0
Top