How to disable data mobile with firemonkey Rad 10.3?

127 Views Asked by At

I am looking to disable mobile data, with firemonkey (Rad 10.3), I have seen several posts, but I have not been able to find a solution.

I have reviewed these posts:

Enable/Disable mobile data

The setMobileDataEnabled method is no longer callable as of Android L and later

Firemonkey enable GPS service for Android

TCP/IP Indy Chat Delphi 10.3.3 FMX (using internet, not only LAN)

How to call setMobileDataEnabled()

but this information not function with Fmx. Pls any idea.

procedure TFClient.Button2Click(Sender: TObject);
var
TelephonyManager  : JTelephonyManager;
red                : JString;
t_typored          : integer;

begin

TelephonyManager := TJTelephonyManager.Wrap(TAndroidHelper.context.getSystemService
(TJContext.JavaClass.TELEPHONY_SERVICE));
try

PermissionsService.RequestPermissions([PermissionReadPhoneState],
procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
begin

  if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
  begin


     if TelephonyManager.isDataEnabled then
      begin

        TelephonyManager.setDataEnabled(False); //--->this code not function

        ShowMessage('Datos desactivados');

     end

 end
 else
    ShowMessage('Permission Denied');


end);  //End permission


except
 on E: Exception do
 begin
       ShowMessage('CONNECTION ERROR! ' + E.Message);
 end;
end;
end;

I´m use the next code for permission:

private const
{$IFDEF ANDROID}
PermissionAccessFineLocation = 'android.permission.ACCESS_FINE_LOCATION';
PermissionReadPhoneState     = 'android.permission.READ_PHONE_STATE';
PermissionInternet           = 'android.permission.INTERNET';
PermissionAccesNetworkState  = 'android.permission.ACCESS_NETWORK_STATE';
PermissionChangeNetworkState  = 'android.permission.CHANGE_NETWORK_STATE';
PermissionModifyPhoneState    = 'android.permission.MODIFY_PHONE_STATE';
{$ENDIF}

I test this other code, but not function

      t_typored:=MobileNetwork.getType;  // 1-wifi 0- mobil data
      red:= MobileNetwork.getTypeName;   //name type
      ConnectivityManager.stopUsingNetworkFeature(t_typored,red);
      

Could someone help me?, Thanks.

0

There are 0 best solutions below