0

I don't think there's a way to do this but I wanted to double check.

I have some web content being loaded in a chrome custom tab, and the content could be sensitive in nature.

The android app has a PIN screen, which we would like to show when the custom tab resumes, but I don't see any way to do this, or believe it's possible.

Can this be done with custom tabs, or will the web app need to implement their own PIN screen?

Ben987654
  • 3,280
  • 4
  • 27
  • 50
  • well, assuming this custom tab is opened in your app you can always lock screen from calling `Activity`s side. but if you manage only web side I'm also affraid that you don't have option to force-lock device... – snachmsm Oct 06 '21 at 19:29
  • @snachmsm ya it's in my app. I've found that there's a onNavigationEvent callback that I might be able to work with, I just can't get it to work yet. The whole CustomTabServiceConnection isn't triggering onCustomTabsServiceConnected yet. Hopefully once that's working the callback will function as i need. Otherwise my app doesn't trigger any lifecycle events when the custom tab resumes – Ben987654 Oct 06 '21 at 21:05
  • Issue was with targeting SDK 30. I guess something to do with the chrome package and the new package manager changes it didn't like so the service wouldn't bind. Tomorrow i can figure out if my entire workflow will work. – Ben987654 Oct 06 '21 at 23:24

1 Answers1

0

There's a callback when you bind a custom tab service that will alert you when a tab is shown (5) / hidden (6)

CustomTabsServiceConnection customTabsServiceConnection = new CustomTabsServiceConnection() {
            @Override
            public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
                client = customTabsClient;
                client.warmup(0L);
                customTabsSession = client.newSession(new CustomTabsCallback() {
                    @Override
                    public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) {
                        super.onNavigationEvent(navigationEvent, extras);
                    }
            }
}

You can then bind this and the callbacks will start triggering when you use it when launching your tabs (SDK <= 29, it will be different on 30)

    String packageName = CustomTabsClient.getPackageName(this, null);
    boolean didSucceed = CustomTabsClient.bindCustomTabsService(this, packageName, mCustomTabsServiceConnection);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(customTabsSession);
Ben987654
  • 3,280
  • 4
  • 27
  • 50