Watch, Follow, &
Connect with Us

Welcome, Guest
Guest Settings
Help

Thread: (TAndroidService) in C++Builder Berlin



Info Your thread was posted successfully, but there will be a short delay before it is viewable in the forum.


Permlink Replies: 1 - Last Post: May 20, 2017 4:34 AM Last Post By: Lena Ilicheva
Lena Ilicheva

Posts: 71
Registered: 9/22/06
(TAndroidService) in C++Builder Berlin
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 11, 2017 8:49 AM
I'm using this article:
https://community.embarcadero.com/blogs/entry/how-to-use-android-service-tandroidservice-in-c-builder
I have a real device beacon. I created a service on pascal:
 
unit BeaconServiceUnit;
 
interface
 
uses
  System.SysUtils,DateUtils,
  System.Classes,
  System.Android.Service,
  AndroidApi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Os, System.Beacon, System.Notification, System.Beacon.Components,
  System.Bluetooth;
 
type
  TBeaconServiceDM = class(TAndroidService)
    Beacon1: TBeacon;
    NotificationCenter1: TNotificationCenter;
    function AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer;
    procedure Beacon1BeaconEnter(const Sender: TObject; const ABeacon: IBeacon;
      const CurrentBeaconList: TBeaconList);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  BeaconServiceDM: TBeaconServiceDM;
 
implementation
 
{%CLASSGROUP 'FMX.Controls.TControl'}
 
{$R *.dfm}
 
uses
  Androidapi.JNI.App;
 
function TBeaconServiceDM.AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags,
  StartId: Integer): Integer;
begin
   Beacon1.Enabled := True;
   Result := TJService.JavaClass.START_STICKY;
end;
 
procedure TBeaconServiceDM.Beacon1BeaconEnter(const Sender: TObject;
  const ABeacon: IBeacon; const CurrentBeaconList: TBeaconList);
var
  a_notification_: TNotification;
begin
  a_notification_ := NotificationCenter1.CreateNotification;
  try
    a_notification_.Name := 'My Android Service1';
    a_notification_.Title := 'Android Service';
    a_notification_.AlertBody := 'Hello!!!';
    a_notification_.FireDate := IncSecond(Now, 1);
    NotificationCenter1.ScheduleNotification(a_notification_);
  finally
    a_notification_.Free;
  end;
end;
 
 
end.


Add this service in c++ app.
–°++ app:
 
void __fastcall TForm1::FormShow(TObject *Sender)
{
 TLocalServiceConnection::StartService(L"BeaconService");
}
 
void __fastcall TForm1::NotificationCenter1ReceiveLocalNotification(TObject *Sender,
		  TNotification *ANotification)
{
  Label2->Text = ANotification->AlertBody;
}


However, nothing happens. Where can there be a mistake? Android 4.4.4

P.S.
Standard AndroidService example on pascal:
C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Multi-Device Samples\Device Sensors and Services\AndroidBeaconServiceDemo
Lena Ilicheva

Posts: 71
Registered: 9/22/06
Re: (TAndroidService) in C++Builder Berlin
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 20, 2017 4:34 AM   in response to: Lena Ilicheva in response to: Lena Ilicheva
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02