Office Hours — Today, March 16

Tuesday, March 14

Mar 16
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:35 PM
Andrew W.
has entered the room
Andrew W.
hello
Mark M.
hello, Andrew!
how can I help you today?
(assuming the question isn't "how can I fix my bracket, as I had Minnesota in the Final Four?")
Andrew W.
Well, I've got a problem with adapting my app to work with Android N.
7:40 PM
Andrew W.
What's the best way to do this, send the text or the file?
Mark M.
what text and what file are you referring to?
Andrew W.
lmfao about Minnesota.
Mark M.
again, what text and what file are you referring to?
Andrew W.
7:45 PM
Andrew W.
This won't work on anything above API 23, and I'm wondering if I'll be able to keep it working in Android N without using any additional permissions.
Pretty sure the trouble starts at instChromium()
Mark M.
that won't work on Android 7.0+
due to the FileUriExposedException that it will throw
if your targetSdkVersion is 24+
also, you should not be deleting the APK right away, as the installer will not have had a chance to use it yet (though that's a problem on all versions of Android, not unique to 7.0+)
what is your targetSdkVersion? and what are your exact symptoms?
7:50 PM
Andrew W.
Target sdk is 25 and symptoms are 'failed to find configured root that contains /data/data/com.anddevw.getchromium/files/getChromium/chrome-android/apks/ChromePublic.apk'
Mark M.
oh, wait, this file is on internal storage
that should fail on all versions of Android, as the app installer does not have access to your app's portion of internal storage
your error is indicative of FileProvider, but you are not using that
are you sure that I am working with the correct file?
Andrew W.
the error is from the modified version of the file i just sent you.
Mark M.
ah, OK
your FileProvider metadata would need a <files-path> element
Andrew W.
so to get where i need to be from what i sent you, what would you recommend?
Mark M.
well, FileProvider
you'll need that on Android 7.0+ for ACTION_INSTALL_PACKAGE
however, you *can't* use that on older versions for ACTION_INSTALL_PACKAGE, because Google ignored my bug report for years
so, you'll need to do a Build.VERSION.SDK_INT check to determine which flavor of Uri to create
then, if you fix the FileProvider metadata XML to eliminate that error, you should be in better shape
Andrew W.
Mark M.
use <files-path>, not <external-path>
7:55 PM
Andrew W.
this is the one currently giving me the error i had mentioned
Mark M.
and either eliminate the path attribute or try cutting it back to "getChromium/apks"
Andrew W.
aha
chike m.
has entered the room
chike m.
Hi
Mark M.
Andrew: let me take a question from chike, and I will be back with you in a bit
Andrew W.
how's it going
Mark M.
chike: your turn! do you have a question?
Andrew W.
no problem
chike m.
yes, concerning the MVP pattern.
what are your thoughts on retaining the presenter?
when there is a configuration change
Mark M.
I do not claim to be an expert on MVP
and so I cannot really answer your question, sorry!
chike m.
oh!
Mark M.
my understanding is that retaining the presenter is a typical approach for MVP with Android, but, again, GUI architecture patterns are not my area of expertise
chike m.
ok Mark. Thanks
Mark M.
since I could not help on that one... do you have another, non-MVP question?
8:00 PM
chike m.
no.
Mark M.
OK, again, sorry
I will switch back to Andrew -- if you come up with another question, let me know
chike m.
alright
Mark M.
Andrew: back to you! do you have another question?
chike m.
has left the room
Mark M.
Andrew: do you have another question?
Andrew W.
possibly...testing the changes
Mark M.
OK
8:05 PM
Andrew W.
so it seems to be almost there, but i'm now getting 'Package installer keeps stopping'
Mark M.
make sure you call addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) on the Intent before calling startActivity()
otherwise, the installer won't have rights to read the APK given the Uri
Andrew W.
View paste (1 more line)
 File apkPath = new File(GetChromium.this.getFilesDir(), "getChromium/chrome-android/apks");
        File apkFile = new File(apkPath, "ChromePublic" + ".apk");
        Uri apkUri = FileProvider.getUriForFile(this, "com.anddevw.getchromium.fileprovider", apkFile);


        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setData(apkUri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if (intent.resolveActivity(getPackageManager()) == null) {
        } else {
            this.startActivity(intent);
            deleteAPk();
        }
...
skipped the first line: private void instChromium () {
Mark M.
don't call setFlags() twice in succession
as the second one wipes out the first one
either use addFlags(), or use a single setFlags() call with a | operator
Andrew W.
ok
8:10 PM
Andrew W.
now it's giving 'There was a problem parsing the package.'
View paste
w       intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Mark M.
OK, the change in message indicates that the Uri is working, at least sort of
did you get rid of the deleteAPk() call?
because it's unrealistic to expect the installer to be able to install from a deleted file... :-)
Andrew W.
that just gets rid of the second apk they package together w the Chromium apk in the zip file. it never deletes the installed apk
8:15 PM
Mark M.
oh, right, that's a different file -- sorry, I missed that
you might temporarily drop your targetSdkVersion below 24, use Uri.fromFile(), and see if things work
if you get the same error, then there's an issue with the APK itself that you are trying to install
if it works, then there's something still amiss with the FileProvider setup, though I'm not sure what
Andrew W.
will Google still allow it for installs on people running N?
Mark M.
sure, for older apps
Andrew W.
View paste
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.anddevw.getchromium.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
        </provider>
Mark M.
that manifest entry looks fine
Andrew W.
and provider_paths.xml
View paste
<provider android:name="android.support.v4.content.FileProvider"
    android:authorities="com.anddevw.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
Mark M.
you have two FileProviders?
that may be a problem
Andrew W.
file_paths.xml and provider_paths.xml
Mark M.
those are both manifest entries
for the same component, with different authorities
Andrew W.
aha
Mark M.
if you have both of those manifest entries in the same app's manifest... I'm surprised that it compiles
8:20 PM
Andrew W.
it would be nice if it didn't.
so should i cut one or both of the entries?
Mark M.
get rid of one, whichever one is the one that you are not using
your Java code is referring to one of those authorities
keep the <provider> for that authority
comment out the <provider> for the other authority
and see if that helps
(meanwhile, I've made myself a note to try reproducing your dual-<provider> setup, as if that compiles and installs, that's seriously messed up)
Andrew W.
you are possibly the only person anywhere who knows anything about this.
Mark M.
oh, I doubt that
I can name at least one other person outside of Google, as I worked on an issue about ACTION_INSTALL_PACKAGE not working at all for N last summer
8:25 PM
Andrew W.
well, so two, but there's not a lot of info floating around
Mark M.
yeah, well, there's that
apps installing apps is a bit of a niche area
Andrew W.
sorry, that was an accident
in general, what does a problem parsing the package mean?
8:30 PM
Mark M.
that's kinda a catch-all error
usually, I interpret it as it was able to at least read part of the APK, but it thinks that the APK is malformed
Andrew W.
interesting. well, thanks a million, Mark. i'll be renewing my subscription because this a tremendous help.
Mark M.
thanks!
you might try writing a test case to confirm that you can read from your own FileProvider, and that the results match
I know FileProvider works, or at least worked, with ACTION_INSTALL_PACKAGE
Andrew W.
yeah, it used to work.
i'll try writing the test case
Mark M.
alas, that's a wrap for today's chat
the transcript will go up on https://commonsware.com/office-hours/ shortly
the next chat is Saturday at 4pm US Eastern
Andrew W.
have a good one
Mark M.
you too!
Andrew W.
has left the room
Mark M.
turned off guest access

Tuesday, March 14

 

Office Hours

People in this transcript

  • Andrew Wright
  • chike mgbemena
  • Mark Murphy