Stream: smart/health-cards
Topic: app to app on android: what intent filters are apps using?
Isaac Vetter (Oct 13 2021 at 20:19):
We've noticed that some wallet apps don't successfully launch with our .smart-health-card file export on Android. The spec only states the MIME type to use (application/smart-health-card). What Android intents and intent filters are people using?
cc / @Oliver Pang
Isaac Vetter (Oct 13 2021 at 20:22):
Ours is something like:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setDataAndType(uri, "application/smart-health-card");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(Intent.createChooser(intent, ...
Josh Mandel (Oct 13 2021 at 20:29):
@James Kizer
James Kizer (Oct 13 2021 at 21:29):
Based on our read of the Android docs, ACTION_VIEW
seems like the more appropriate choice.
The description of ACTION_VIEW
is:
Display the data to the user. This is the most common action performed on data -- it is the generic action you can use on a piece of data to get the most reasonable thing to occur. For example, when used on a contacts entry it will view the entry; when used on a mailto: URI it will bring up a compose window filled with the information supplied by the URI; when used with a tel: URI it will invoke the dialer.
Our take on that is to "display this data in another app"
The description of ACTION_SEND
is:
Deliver some data to someone else. Who the data is being delivered to is not specified; it is up to the receiver of this action to ask the user where the data should be sent.
Our take on that is "send this data to another person"
Regardless of which intent you ultimately choose, CommonHealth is set up handle both ACTION_VIEW
and ACTION_SEND
. We created a test app to ensure that CommonHealth can handle these intents and including code below for how we configure them.
For ACTION_VIEW
:
val shareableUri = SHCContentProvider.createShareableUri()
return Intent(Intent.ACTION_VIEW).apply {
setDataAndType(shareableUri, "application/smart-health-card")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
For ACTION_SEND
:
val shareableUri = SHCContentProvider.createShareableUri()
return Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_STREAM, shareableUri)
type = "application/smart-health-card"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
After updating the ACTION_SEND
code to use setDataAndType
rather than putExtra(Intent.EXTRA_STREAM, shareableUri)
and type = "application/smart-health-card"
, CommonHealth was no longer listed as an application capable handling the intent. Also, comparing your implementation against the docs here, I'd suggest trying the putExtra(Intent.EXTRA_STREAM, shareableUri)
and type = "application/smart-health-card"
approach.
Also note that we use startActivity
instead of startActivityForResult
as well.
James Kizer (Oct 13 2021 at 21:30):
We've also seen some reports of users having trouble exporting data from their MyChart app into CommonHealth, so it would be great if we could hop on a call to debug
Oliver Pang (Oct 13 2021 at 22:10):
Appreciate the writeup! The EXTRA_STREAM approach does seem more in-line with the docs so we'll definitely try it and let you know how it goes.
Regarding ACTION_VIEW vs ACTION_SEND, We've personally chose ACTION_SEND as we're sending the user SHC data to another app for ownership. ACTION_VIEW does definitely make sense as well - especially reading this excerpt
It is the generic action you can use on a piece of data to get the most reasonable thing to occur.
Curious if we have other opinions in this chat as well
Josh Mandel (Oct 13 2021 at 23:46):
I think it'd be worth including notes in the spec, once we get a shared perspective ironed out.
Oliver Pang (Oct 15 2021 at 17:15):
Worked like a charm James!
Verified I was able to export my SHC to CommonHealth with my personal MyChart account using that tweak.
From a bit of testing - I'd propose we prefer the ACTION_SEND approach over ACTION_VIEW.
ACTION_SEND seems to be supported by a variety of apps (e.g. Google Drive, GMail, OneDrive) for sharing or uploading to cloud - whereas view lacks that. It'll be a bit more flexible for the user.
It may be worthwhile to include a suggested intent filter config as well in the spec- to be extra explicit.
Isaac Vetter (Oct 15 2021 at 18:51):
Oliver, James, would that be something like ... ?
<activity android:name="ShareActivity" android:exported="false">
<!-- This activity handles "SEND" actions with text data -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/smart-health-card"/>
</intent-filter>
James Kizer (Oct 15 2021 at 19:40):
RE: ACTION_SEND vs ACTION_VIEW, that's fine, but we also need to make wallets aware that other applications on the device (i.e., Files, Gmail) utilize the ACTION_VIEW intent. Also, sometimes the mime type come through as application/octet-stream
from some applications (e.g., from Files), so we might want to include that.
Our intent filters to support this functionality are as follows:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" android:scheme="content" android:mimeType="application/smart-health-card" />
<data android:host="*" android:scheme="content" android:mimeType="application/octet-stream" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/smart-health-card" />
</intent-filter>
Isaac Vetter (Oct 15 2021 at 20:08):
@James Kizer , @Oliver Pang -- how's this look: https://github.com/smart-on-fhir/health-cards/pull/197 ?
James Kizer (Oct 15 2021 at 20:12):
Thanks for putting this PR up @Isaac Vetter, left some feedback
Oliver Pang (Oct 15 2021 at 20:14):
Good point James - I did notice that during initial testing as well. Good thing to note.
I don't have any concerns with the PR Isaac. Agreed with the PR comments from James
Last updated: Apr 12 2022 at 19:14 UTC