23-03-2020, Saat: 16:17
Merhaba iyi günler,
Değişik bir sorunum var Android servis yazıyorum Server kontrolu yapıp ona göre bildirim atıyorum.
Daha önce Unidac bileşenleri ile yaptığımda hiçbir sıkıntı yoktu fakat Rest bileşenleri ile yapmaya çalıştım bu sefer kendi cihazım android 8.1 de çok güzel çalışıyorken android 9 ve 10'da tepki vermiyor uygulama açık olsa bile çalışmıyor(Servis arka planda çalışmakta).
Servis Kodlarını paylaşıyorum, bu sorun sdk ayarlarından olabilirmi android 8 yüklüydü sadece şuan android 10 sdksını yükledim ama sorun halen aynı.
Değişik bir sorunum var Android servis yazıyorum Server kontrolu yapıp ona göre bildirim atıyorum.
Daha önce Unidac bileşenleri ile yaptığımda hiçbir sıkıntı yoktu fakat Rest bileşenleri ile yapmaya çalıştım bu sefer kendi cihazım android 8.1 de çok güzel çalışıyorken android 9 ve 10'da tepki vermiyor uygulama açık olsa bile çalışmıyor(Servis arka planda çalışmakta).
Servis Kodlarını paylaşıyorum, bu sorun sdk ayarlarından olabilirmi android 8 yüklüydü sadece şuan android 10 sdksını yükledim ama sorun halen aynı.
unit Unit3;
interface
uses
System.SysUtils,
System.Classes,
System.Android.Service,
AndroidApi.JNI.GraphicsContentViewText,
AndroidApi.JNI.Os, System.Notification, Data.DB, MemDS, DBAccess, Uni,
REST.Types, REST.Client, Data.Bind.Components, Data.Bind.ObjectScope ;
type
TDMm = class(TAndroidService)
NotificationC: TNotificationCenter;
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
procedure AndroidServiceCreate(Sender: TObject);
function AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
private
procedure ThreadingProcRun(const ARunProc: TProc;
const SleepMilliSecond: Integer);
procedure NotificationCreate;
public
{ Public declarations }
end;
var
DMm: TDMm;
implementation
uses AndroidApi.JNI.App, NetworkState, RootUnit;
{%CLASSGROUP 'FMX.Controls.TControl'}
{$R *.dfm}
procedure TDMm.AndroidServiceCreate(Sender: TObject);
Var
xNotification: TNotification;
begin
ThreadingProcRun(NotificationCreate, 60000);
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
aNotification: TNotification;
NS: TNetworkState;
A: TRootDTO;
begin
A := TRootDTO.Create;
NS := TNetworkState.Create;
if not NS.IsConnected then
begin
NS.Free;
exit;
end;
RESTRequest1.Execute;
A.AsJson := RESTResponse1.Content;
if A.Info = '1' then
begin
aNotification := NotificationC.CreateNotification;
try
with xNotification do
begin
AlertBody := 'Bildirim Deneme!';
NotificationC.ScheduleNotification(aNotification);
end;
finally
aNotification.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.