10-06-2020, Saat: 13:33
Merhaba,
Başlıktada belirttiğim gibi bir Arkaplan servisi yazdım Telefona apk olarak yüklediğimde çok güzel çalışıyor, Google playe attım ve arka plan servisi etkin çalışıyor ama bildirim gelmiyor neden olabilir?
Başlıktada belirttiğim gibi bir Arkaplan servisi yazdım Telefona apk olarak yüklediğimde çok güzel çalışıyor, Google playe attım ve arka plan servisi etkin çalışıyor ama bildirim gelmiyor neden olabilir?
unit Uservis;
interface
uses
System.SysUtils,
System.Classes,
System.Android.Service,
AndroidApi.JNI.GraphicsContentViewText,
AndroidApi.JNI.Os, System.Notification, REST.Types, REST.Client, Data.Bind.Components, Data.Bind.ObjectScope,
AndroidApi.Helpers,
AndroidApi.JNI.App, System.Net.HttpClient, System.Net.HttpClientComponent, inifiles, System.IOUtils;
type
TDMm = class(TAndroidService)
NotificationC: TNotificationCenter;
procedure AndroidServiceCreate(Sender: TObject);
function AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer;
private
procedure NotificationCreate;
procedure ThreadingProcRun(const ARunProc: TProc; const SleepMilliSecond: Integer);
{ Private declarations }
public
{ Public declarations }
end;
var
DMm: TDMm;
implementation
{%CLASSGROUP 'FMX.Controls.TControl'}
{$R *.dfm}
uses NetworkState, RootUnit;
procedure TDMm.AndroidServiceCreate(Sender: TObject);
begin
ThreadingProcRun(NotificationCreate, 5000);
end;
function TDMm.AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer;
begin
Result := TJService.JavaClass.START_STICKY;
end;
procedure TDMm.NotificationCreate;
var
xNotification: TNotification;
NS: TNetworkState;
A: TRootDTO;
NetHTTPClient: TNetHTTPClient;
rsp: IHTTPResponse;
cevap: String;
ini1: TINIFile;
i: integer;
recordd: integer;
Token: string;
Adi: string;
begin
A := TRootDTO.Create;
NS := TNetworkState.Create;
if not NS.IsConnected then
begin
NS.Free;
exit;
end;
ini1 := Tinifile.Create(TPath.Combine(TPath.GetDocumentsPath, 'NorthPlus.ini'));
recordd := (ini1.ReadString('ArkaPlan', 'Record', '').ToInteger) - 1;
for I := 0 to recordd do
begin
Token := ini1.ReadString('ArkaPlan', i.ToString + 'Token', '');
Adi := ini1.ReadString('ArkaPlan', i.ToString + 'Adi', '');
NetHTTPClient := TNetHTTPClient.Create(nil);
try
try
rsp := NetHTTPClient.Get('http://31.192.215.124/BL.php?token=' + Token);
except
rsp := NetHTTPClient.Get('http://31.192.215.124/BL.php?token=' + Token);
end;
cevap := rsp.ContentAsString();
A.AsJson := cevap;
finally
NetHTTPClient.Free;
end;
xNotification := NotificationC.CreateNotification;
if A.BD_15 = '1' then
begin
xNotification.Title := Adi;
xNotification.AlertBody := 'ozelmesaj!';
NotificationC.PresentNotification(xNotification);
xNotification.DisposeOf;
end;
if A.BD_14 = '1' then
begin
xNotification.Title := Adi;
xNotification.AlertBody := 'motor!';
NotificationC.PresentNotification(xNotification);
xNotification.DisposeOf;
end;
end;
end;
procedure TDMm.ThreadingProcRun(const ARunProc: TProc; const SleepMilliSecond: Integer);
begin
TThread.CreateAnonymousThread(
procedure()
begin
while True do
begin
ARunProc;
sleep(SleepMilliSecond);
end;
end).Start;
end;
end.
Muharrem ARSLAN

