Skip to content

Instantly share code, notes, and snippets.

@thanhtungka91
Last active October 6, 2021 01:51
Show Gist options
  • Save thanhtungka91/56e9e26f7254a4ba62fb8078e1afb73e to your computer and use it in GitHub Desktop.
Save thanhtungka91/56e9e26f7254a4ba62fb8078e1afb73e to your computer and use it in GitHub Desktop.
TWA start a new activity
protected CustomTabsSession getSession(CustomTabsClient client) {
return client.newSession((CustomTabsCallback) null, 96375);
}
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) {
CustomTabsSession mSession = MainActivity.this.getSession(client);
if (mSession == null) {
Toast.makeText(MainActivity.this,
"Couldn't get session from provider.", Toast.LENGTH_LONG).show();
}
Uri url = MainActivity.this.getLaunchingUrl();
// custom url for notification
if (appLink != null) {
String applinkString = appLink.toString();
// add sub router android to uri
url = Uri.parse(applinkString);
}
Log.d("TWALink", url.toString());
TrustedWebActivityIntentBuilder builder = new TrustedWebActivityIntentBuilder(
url);
Intent intent = builder.build(mSession).getIntent();
MainActivity.this.startActivity(intent);
MainActivity.this.mTwaWasLaunched = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment