Android - Using URI permissions with broadcast -


I am trying to test if the URI permission works with the broadcast.

I have the following code in the first app activity:

  intent = new intent ("com.android.testintent.app.bcast"); Intent.setData (contentUri); Intent.setFlags (Intent.FLAG_GRANT_READ_URI_PERMISSION); SendBroadcast;  

The content URI has been received from a file provider.

  & lt; Provider Android: name = "android.support.v4.content.FileProvider" Android: Authorization = "com.android.provider.DataSharing" Android: export = "false" android: grant URI question = "true" & gt; & Lt; Meta-Data Android: name = "android.support.FILE_PROVIDER_PATHS" Android: resource = "@ xml / paths" /> & Lt; / Provider & gt; ContentUri = FileProvider.getUriForFile (getApplicationContext (), "com.android.provider.DataSharing", / * path of file * /); // file path is correct - I tested it with activity  

In the app received in the broadcast:

  & lt; Receiver Android: name = ". MyReceiver" Android: enabled = "true" android: export = "true" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "com.android.testintent.app.bcast" /> & Lt; / Intent-Filter & gt; & Lt; / Receiver & gt;  

Receiver code - onReceive ():

  Toast. Make Text (Reference, "BCC - Received", Toast. LNNHHLLG). Show (); Uri Uuri = Intent .getData (); If (uri! = Null) {try {InputStream inputStream = context.getContentResolver () OpenInputStream (uri); } Hold (exception e) {log d. ("Test", "nonsense - exception:" + e); }}  

When I clear the URI from the first app, the broadcast reaches the receiver and I can see the toast message. However, when the URI is not empty, my receiver does not even receive the broadcast.

Can anyone tell because of this behavior?

Edit :

I have edited the receiver:

   & Lt; Data Android: mimeType = "image / jpeg" /> & Lt; / Intent-Filter & gt; & Lt; / Receiver & gt;  

I have added the mime type I did this on the basis of a rule (see)

  A purpose in which a URI And an MIM type (either explicit or predictable by the URI) passes the test of the MIME type only that matches the one type listed in the filter so that it passes the URI part of the test or if its URI filter Matches URI in Or if it does not specify the content or file: URI and URI filter. In other words, a component is considered to support the content: and file: data if its filter has only one MIME type list  

Now I get an exception in the receiver :

  D / Test: Baccast - Exception: java.lang.SecurityException: Permission denied: ProcessRecord from {52 9a7b60 1593: com.android. From Opening Provider Android .support.v4.content.FileProvider. Testintent.app/u0a55} (PAD = 1593, UID = 10055) which is not exported from UID 10059  

If I Try to export Rovaider do, Android describes an exception that is not allowed to export providers.

What can I do to solve it?

The reason for this is that you & lt; Intent-filter & gt; . Your & lt; Intent-Filter & gt; Matching only on action strings is a URI Data & gt; There is a need to qualify for the element, which indicates that you support the content plan > correct mime type


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -