Office Hours — Today, August 23

Tuesday, August 21

Aug 23
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Jeffrey G.
has entered the room
Jeffrey G.
hi.
Mark M.
hello, Jeffrey!
how can I help you today?
Jeffrey G.
I have my office computer today so I thought I would share some of my intent-related stuff.
9:05 AM
Mark M.
OK
Jeffrey G.
here is an idea of some of the things i tried.
Mark M.
those <intent-filter> elements are on <receiver>
that will not work, for responding to startActivity() calls from a Web browser
you need to have <intent-filter> elements on an <activity> to respond to startActivity() calls
and at best a Web browser will use startActivity() when the user clicks on a link
Jeffrey G.
okay, good to know. I tried this as a desperation move. i am going to upload the one i have on my activity next.
but your chatroom is stuck on "finishing upload" so I can't upload another file.
i'll just copy paste.
View paste
    [Activity(Label = "RecipeActivity")]
    [IntentFilter(new [] {  Intent.ActionSend  },
                    Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault },
                    DataScheme = "http",
                    DataHost = "capstonelogistics.com",
                    DataPathPrefix = "/",
                    DataPathPattern = ".*",
                    AutoVerify=false  )]
    public class RecipeActivity : Activity
this is Xamarin C# but i'm sure you get the idea as far as the intent filter is concerned.
9:10 AM
Mark M.
does Xamarin code-generate the <intent-filter>? I haven't used Xamarin
Jeffrey G.
yeah, it's supposed to.
i'm tempted to just define this in the androidmanifest.xml instead.
just in case something's not working right with how it converts the attributes.
Mark M.
you can't have both pathPrefix and pathPattern
Jeffrey G.
that's how you would do it in java anyway, right? just create your java activity class and then define the intent filter in the xml?
Mark M.
and in this case you don't need either of them, if you want to respond to everything in that domain
Jeffrey G.
okay. I did try them separately before.
okay.
what is the minimum I need?
Mark M.
yes, we put the <intent-filter> elements directly in AndroidManifest.xml
scheme and host
making sure that the scheme matches the scheme that you intend to use (you have http, which will not match https)
if you wanted to stick with the Xamarin-generated manifest, try to find where it is being generated, so you can examine the result and confirm that it matches what you expect
9:15 AM
Jeffrey G.
could i deconstruct the APK file and look for the manifest contained within it?
Mark M.
the easiest solution for that is to install https://play.google.com/store/apps/details?id=c...
Jeffrey G.
i could alternatively see where on my build machine it is combining the AndroidManifest.xml along with the stuff it is generating from the class attributes.
Mark M.
in the "..." menu for your app's entry in the Applications Info app, you will find an option to view the manifest of the installed app
Jeffrey G.
oh, so i could view the manifest directly from an installed app?
nice.
Mark M.
kinda handy... particularly for apps that aren't yours :-)
Jeffrey G.
lol.
is it not possible to modify an existing APK's manifest since the binary is signed or is there a way around that, even if it involves somehow rebuilding it?
i'd like to add BROWSABLE to an existing app that already does what I want.
Mark M.
modding existing apps isn't in my area of expertise
Jeffrey G.
your chat room is still stuck on "finishing upload."
9:20 AM
Mark M.
sorry, must be a Campfire bug
Jeffrey G.
i'm going to try that applications info app.
Mark M.
there are other ways to get at the manifest, but for casual use, Applications Info is the simplest solution
some of the Play Store comments indicate that people encounter crashes, though I haven't had a problem personally
Jeffrey G.
if all is needed is scheme and host, how does android find your app if you don't declare package?
does it just match the host you declare to the host in the clickable link?
Mark M.
oh, sorry, I thought that you were referring only to the non-standard elements that you added
View paste
[IntentFilter(new [] {  Intent.ActionSend  },
                    Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault },
                    DataScheme = "http",
                    DataHost = "capstonelogistics.com",
                    AutoVerify=false  )]
AutoVerify=false should be the default, so you can probably skip that one too
Jeffrey G.
i would like to know the minimum "stuff" i must add to this intent-filter to at least get it to work locally for test purposes.
i understand there may be more stuff required in production.
Mark M.
oh, whoops, you are using ActionSend
change that to what I assume Xamarin refers to as ActionView
Jeffrey G.
i don't necessarily need to use ActionSend if there are other options.
Mark M.
View paste
so, try:

[IntentFilter(new [] {  Intent.ActionView  },
                    Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault },
                    DataScheme = "http",
                    DataHost = "capstonelogistics.com" )]
(give or take some punctuation, as I am not a C# guy)
Jeffrey G.
will that still popup a chooser dialog?
Mark M.
yes
it should list your app, Web browser(s), and anything else that handles http URLs that include that host and either support all MIME types or support whatever MIME type is associated with your URL
9:25 AM
Mark M.
later, you will probably want to use one of path, pathPrefix, or pathPattern, to limit the URLs that your app claims to handle
Jeffrey G.
it looks like the app's manifest was updated. i see the filter but the name is decorated with a large letter/number combination in front.
i am gong to see if i can copy/paste this from the app to somewhere.
Mark M.
by the name, do you mean android:name?
if so, that may be a Xamarin thing, for how they code-generate Java-style classes from the C# code
9:30 AM
Jeffrey G.
yes.
View paste
<activity android:label="RecipeActivity" android:name="md5d1349008731dcef7626f3904d490892a.RecipeActivity">
<intent-filter android:autoVerify="false">
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="capstonelogistics.com"/>
<data android:pathPattern=".*"/>
<data android:pathPrefix="/"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
at least i can confirm the xamarin c# attributes are getting placed into the manifest.
Mark M.
that lines up with your original IntentFilter that you pasted in
right
9:35 AM
Jeffrey G.
View paste
I have tried variants of the following with no luck:

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://capstonelogistics.com"
is there anything else other than the intent filter in the manifest that android needs to make this association work?
Mark M.
your current <intent-filter> is not using VIEW -- it is using SEND
if your objective is to try launching your existing activity with its existing <intent-filter>, replace -a android.intent.action.VIEW with -a android.intent.action.SEND
Jeffrey G.
ahh good point.
how do they differ? do they both cause a chooser to appear?
Mark M.
they're not strictly related
ACTION_SEND is mostly for "share" menu options
Jeffrey G.
if you point to a page in your book I can read about it offline.
Mark M.
and, among other things, it would never have a Uri in the data facet of the Intent
"Intents, IntentFilters" discusses ACTION_SEND
page 799 of Version 8.13 of the book
more importantly, if you want to respond to a click on a link in a browser, that will be ACTION_VIEW, not ACTION_SEND
9:40 AM
Jeffrey G.
ok.
okay, so if I updated it to ACTION_VIEW, remote pattern and prefix, and just use the minimum you suggest, I should be able to get it to work, right?
Mark M.
if nothing else, it should work with the adb shell command
Jeffrey G.
I just want to make sure at this point that the filter is all that is needed from Android to make this connect happen, and that I just need to get the invocation stuff working.
Mark M.
in principle, it should work from a suitable link in Chrome
Jeffrey G.
right using adb shell is going to be my first course of action.
and, just to confirm, only activities can be invoked from chrome and not broadcast receivers, correct?
Mark M.
correct
9:45 AM
Jeffrey G.
i have another topic to ask about. if, for some reason, sending my print data this way doesn't work, is there a way for chrome to save it as a file somewhere that is accessible by another app? could i perhaps write a service that monitors a file folder somewhere for new jobs to print?
Mark M.
it's conceivable that your site could generate a file that Chrome then downloads to a user-specified location
I would not expect JavaScript code to be able to directly write to the filesystem, for security reasons
Jeffrey G.
yeah, that's the part i wasn't sure about
Mark M.
another possibility, depending on your scenario, would be to use WebView instead of relying on standalone Chrome, as you can have much tighter integration between your app code and the Web content with a WebView
9:50 AM
Jeffrey G.
ok.
10:00 AM
Mark M.
OK, that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ soonish
the next chat is Saturday at 4pm US Eastern
have a pleasant day!
Jeffrey G.
has left the room
Mark M.
turned off guest access

Tuesday, August 21

 

Office Hours

People in this transcript

  • Jeffrey Gonzales
  • Mark Murphy

Files in this transcript