Fixed
Status Update
Comments
uc...@google.com <uc...@google.com> #2
Thank you for suggesting this enhancement. We value the feedback from our community and hope to review your suggestion in an upcoming sprint.
tn...@google.com <tn...@google.com> #3
Fix pending in Change-Id: I03a0789b8698dc9db5d1351c7a87b821e2c701ab.
I actually did work on this back in 2013 but never checked it in because it had too many false positives (at the time the lint check was implemented as a bytecode visitor and it has to be careful to avoid flagging code fragments where the setType and setData calls (or Intent constructor) are invoked on different codepaths; I came across a lot of that). Anyway, there's better machinery now so I've implemented it for an upcoming 3.2 canary build.
I actually did work on this back in 2013 but never checked it in because it had too many false positives (at the time the lint check was implemented as a bytecode visitor and it has to be careful to avoid flagging code fragments where the setType and setData calls (or Intent constructor) are invoked on different codepaths; I came across a lot of that). Anyway, there's better machinery now so I've implemented it for an upcoming 3.2 canary build.
mm...@commonsware.com <mm...@commonsware.com> #4
Very cool, and many thanks!
Description
Uri uri=FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", output);
Intent myIntent = new Intent(Intent.ACTION_VIEW, uri);
myIntent.setType("text/plain");
myIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(myIntent);
This will cause problems for the *receiving* app, because setType() wipes out the Uri set in the constructor, and so the text editor app will get a null Uri and probably will not handle that especially well.
Ideally, there would be a Lint warning for this scenario: supplying a Uri to an Intent prior to a setType() call on that Intent. At present, neither Lint nor Android Studio inspections point out this problem. The recommended solution would be to use setDataAndType(), supplying the Uri and MIME type in one fell swoop.
(for whatever a "fell swoop" is...)
FWIW, the same basic issue was reported five years ago and was ignored for three years:
Thanks for considering this!