Kobo
Kobo

Reputation: 25

Android:Unable to connect to chromecast from app in development when in kiosk mode

I am developing an app for android12. The app is a kiosk mode and uses startLockTask.

To use the standard Android cast function from the app, to call the cast settings screen.

startActivity(new Intent(ACTION_CAST_SETTINGS));

I can display the settings screen, and I can connect to FireTV, I can connect to Chromecast, but I cannot connect to Chromecast. The connection is still in progress.

I found that a confirmation message “start recording or casting?” is displayed at the time of connection, but it was not displayed on my app.

It does appear when I execute stopLockTask just before the connection, Is there any way to make it appear while using startLockTask?

Upvotes: 2

Views: 47

Answers (1)

Abhinay Gowda
Abhinay Gowda

Reputation: 378

This is actually a known limitation with Android's kiosk mode(Lock Task) mode and system dialogs. However you can handle this by adding cast permission to allowed activities.

You can whitelist specific system UI components in your Device owner settings. You need to use DevicePolicyManager to set this up.

DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
String[] packages = {
    "com.google.android.gms",

*// Google Play Services*

"com.google.android.apps.chromecast.app"

*// Cast related*

};
dpm.setLockTaskPackages(admin, packages);

Please check and update if this works for you.

Upvotes: 1

Related Questions