androiddelphikiosk-mode

How to launch an app from a kiosk app in Android


I started from the Embarcadero template Advanced Android Kiosk Mode that is a kiosk app that launches the device wi-fi settings page. I want to launch another app instead of the wi-fi settings page. So I wrote my procedure to launch the app (following this):

procedure TDashboard.StartSA7;
var
  Intent: JIntent;
begin

  FKioskApp.ActiveOtherActivity := True;

  Intent := TJIntent.Create;

  Intent := MainActivity.getPackageManager.getLaunchIntentForPackage(StringToJString('com.embarcadero.SA7mp'));
  Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); // <-- this might be optional

  if MainActivity.getPackageManager.queryIntentActivities(Intent, TJPackageManager.JavaClass.MATCH_ALL).size > 0 then
    begin
      TAndroidHelper.Context.startActivity(Intent);
      Label2.Text := 'OK!!';
    end
  else
    begin
      Label2.Text := 'NO!!!';
    end;
end;

Well, it does not work.

If the main app, the kiosk app, is not device-owner, and so it is not in kiosk mode, it works and the app com.embarcadero.SA7mp is launched, if the main app is device-owner the secondary app is not launched.

The original code to launch the wi-fi settings page is:

procedure TDashboard.GoToSettings;
var
  LIntent: JIntent;
begin
  FKioskApp.ActiveOtherActivity := True;
  // It is important to set the ActiveOtherActivity flag before opening another application in kiosk mode

  LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_WIFI_SETTINGS);
  LIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); // <-- this might be optional
  TAndroidHelper.Context.startActivity(LIntent);
end;

This code obviously works in kiosk mode.

The secondary app is not a device settings page so perhaps this behaviour is normal.

Someone can help me to solve this problem?

(the target device runs Android 11 and I use Delphi 12.2 patch 2)

Thanks


Solution

  • I have solved the problem. In the main app, the Kiosk one, I had to change the line:

    FKioskApp.StartLockTask(['com.android.settings']);
    

    in:

    FKioskApp.StartLockTask(['com.embarcadero.SA7mp']);
    

    In this way the secondary app is launced and it runs in kiosk mode.