Skip to content

Commit c71cc96

Browse files
authored
Merge pull request #548 from momohatt/custom-launch-url-for-intent
2 parents d763856 + 0a0f753 commit c71cc96

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected void launchTwa() {
226226
.setScreenOrientation(mMetadata.screenOrientation)
227227
.setLaunchHandlerClientMode(mMetadata.launchHandlerClientMode);
228228

229-
Uri intentUrl = getIntent().getData();
229+
Uri intentUrl = getUrlForIntent(getIntent());
230230
if (!launchUrl.equals(intentUrl)) {
231231
twaBuilder.setOriginalLaunchUrl(intentUrl);
232232
}
@@ -394,6 +394,15 @@ protected Map<String, Uri> getProtocolHandlers() {
394394
return Collections.emptyMap();
395395
}
396396

397+
/**
398+
* Override this to define a custom mapping from intent to URL (e.g., based on intent action).
399+
* The returned URL may be further modified by the Protocol Handler support.
400+
*/
401+
@Nullable
402+
protected Uri getUrlForIntent(Intent intent) {
403+
return intent.getData();
404+
}
405+
397406
@Override
398407
public void onEnterAnimationComplete() {
399408
super.onEnterAnimationComplete();
@@ -404,16 +413,16 @@ public void onEnterAnimationComplete() {
404413

405414
/**
406415
* Returns the URL that the Trusted Web Activity should be launched to. By default this
407-
* implementation checks to see if the Activity was launched with an Intent with data, if so
408-
* attempt to launch to that URL. If not, read the
416+
* implementation checks to see if there is a URL specified for the Intent that launched the
417+
* Activity, and if so attempts to launch to that URL. If not, reads the
409418
* "android.support.customtabs.trusted.DEFAULT_URL" metadata from the manifest.
410419
*
411420
* Override this for special handling (such as ignoring or sanitising data from the Intent).
412421
*/
413422
protected Uri getLaunchingUrl() {
414423
Uri defaultUrl = Uri.parse(mMetadata.defaultUrl);
415424

416-
Uri intentUrl = getIntent().getData();
425+
Uri intentUrl = getUrlForIntent(getIntent());
417426

418427
if (intentUrl != null) {
419428
Map<String, Uri> protocolHandlers = getProtocolHandlers();

0 commit comments

Comments
 (0)