RTC Forums
May 14, 2024, 08:03:59 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Push style notification on Android  (Read 5127 times)
Chris Fieldhouse
RTC Expired
*
Posts: 10


« on: November 06, 2017, 06:37:17 PM »

Hi

I was wondering, is it possible to create a push style notification from a Win32 server to an Android app?  I have a need to inform individual Android clients when a server event has happened, if it were a WebApp I would look at WebSockets, but as this is an Android App, I wondered if you had a component that I had missed, or is it possible to use WebSockets from within the Android app?

Many thanks

Chris
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 06, 2017, 06:56:09 PM »

You can use WebSockets on all supported platforms (Win32, Win64, MacOSX, iOS32, iOS64 and Android).

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #2 on: November 06, 2017, 08:06:22 PM »

I used TRtcHttpClient and TRtcDataRequest and it works like a charm. The HttpClient you set to fcm.googleapis.com and you can call it like :

Code:
procedure TDMRTC_GF.SendMobileNotification(const ADestino, AMessage: String);
begin
  RtcDataRequest.Request.Method := 'POST';
  RtcDataRequest.Request.FileName:='/fcm/send';
  RtcDataRequest.Request['Content-Type']:='application/json';
  RtcDataRequest.Request['Authorization']:='key=<insert my google key here>'; // here come your key
  With RtcDataRequest.Request.Info.newRecord('data') do begin
    asText['to']:= ADestino;
    with newRecord('data') do
      asText['message'] := AMessage;
    end;
  RtcDataRequest.Post;
end;

procedure TDMRTC_GF.RtcDataRequestBeginRequest(Sender: TRtcConnection);
begin
  With TRtcDataClient(Sender) do
    Write(Request.Info.asJSON['data']);
end;

procedure TDMRTC_GF.RtcDataRequestDataReceived(Sender: TRtcConnection);
var S: String;
begin
  With TrtcDataClient(Sender) do
    If TrtcDataClient(Sender).Response.Done then begin
      S := TrtcDataClient(Sender).Read;
      CodeSite.Send( csmLevel4, 'Google Response', S);
    end;
end;

Logged
Chris Fieldhouse
RTC Expired
*
Posts: 10


« Reply #3 on: November 07, 2017, 11:00:10 AM »

@Danijel

Thanks for the info.  I don't suppose you can provide a code snippet for how I might initiate the WebSocket client in the Android App?

@HelgeLange

Thanks for the code sample, unfortunately I cannot use Google push as this has to be done on a LAN without using external services.

Many thanks

Chris
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 on: November 07, 2017, 11:27:21 AM »

You can find WebSocket Examples in the "Examples\WebSockClient" and "Examples\WebSockServer" folder (Client and Server) in the RTC SDK package. Even though these Projects use the VCL, because of which they only compile for Windows (since VCL is Windows-only), all RTC components and RTC-specific code used in these Projects should work with all platforms supported by the RTC SDK (Android, iOS, Mac OSX and Windows) when used from a FireMonkey Project.

Best Regards,
Danijel Tkalcec
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 on: November 07, 2017, 12:16:45 PM »

Actually, the Client-side Example for WebSockets is also available as a FireMonkey Project (just checked), but ... since there were a number of changes in FireMonkey between Delphi versions, you will probably need Delphi 10 or later if you wanted to compile it as-is. RTC components and all RTC-specific code should compile with VCL and all FireMonkey versions, though (as already mentioned in my previous reply).

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #6 on: November 07, 2017, 03:40:18 PM »

@HelgeLange

Thanks for the code sample, unfortunately I cannot use Google push as this has to be done on a LAN without using external services.

Wouldn't App Tethering work just nice ?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.025 seconds with 16 queries.