Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   delphi12 / firmonkey / android app (https://www.delphipraxis.net/216730-delphi12-firmonkey-android-app.html)

erich.wanker 19. Feb 2025 11:26

delphi12 / firmonkey / android app
 
Hallo ..ich bin ein bisserl am verzweifeln ;-)

Ich habe eine App - die nix anderes tut als eine java-Background service zu starten .. im manifest habe ich einen hinweis dass der serivice beim booten mitgestartet werden soll

Aber ich bekomme den service nicht zum laufen und die App stürzt sofort nach dem start ab.


die Firmonkey app is wie folgt:
Delphi-Quellcode:
unit MainUnit;

interface

uses
  System.SysUtils, System.Classes, System.UITypes, System.IOUtils,
  FMX.Forms, FMX.Controls, FMX.Types, FMX.StdCtrls, FMX.Edit, FMX.Layouts,
  FMX.Memo, FMX.Objects, Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.App, Androidapi.Helpers, FMX.Controls.Presentation, FMX.DialogService;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure StartService;
  public
    { Public-Deklarationen }
  end;



var
  Form1: TForm1;

implementation

uses
  IniFiles, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os;



procedure TForm1.StartService;
var
  Intent: JIntent;
  ServiceName: string;
begin
Intent := TJIntent.Create;
    ServiceName := JStringToString(TAndroidHelper.Context.getPackageName) + '.MyBackgroundService';

    Intent.setClassName(
      TAndroidHelper.Context.getPackageName,
      StringToJString(ServiceName)
    );

  if TOSVersion.Check(8) then // Android 8+ benötigt Foreground-Service
    TAndroidHelper.Context.startForegroundService(Intent)
  else
    TAndroidHelper.Context.startService(Intent);
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
StartService;
end;

end.
das ganze Projekt (mit JAVA, Manifest und Co.) habe ich als ZIP Datei online gestellt: https://wavi.at/monotify.zip
.

Es wäre SUPER wenn jemand mir helfen könnte - mit Android apps habe ich leider null Erfahrungen

Vielen Dank und schöne Grüße
Erich

erich.wanker 19. Feb 2025 13:13

AW: delphi12 / firmonkey / android app
 
.. habe gerade gesehen dass im Manifest wieder mein Serive und receiver-teil fehelen. Anbei wie ich es eigentlich geplant hätte:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.embarcadero.MONotify"
    android:versionCode="1"
    android:versionName="1.0.0"
    android:installLocation="auto">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="34" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CALL_COMPANION_APP" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND" />
    <uses-permission android:name="android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    <queries>

    </queries>
    <application
        android:persistent="False"
        android:restoreAnyVersion="False"
        android:label="MONotify"
        android:debuggable="true"
        android:largeHeap="False"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme"
        android:hardwareAccelerated="true"
        android:resizeableActivity="true"
        android:requestLegacyExternalStorage="true">

        <service
    android:name=".MyBackgroundService"
    android:enabled="true"
    android:exported="false"
    android:foregroundServiceType="dataSync" />

        <receiver
            android:name=".BootReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>



        <!-- Trigger Google Play services to install the backported photo picker module. -->
        <service
            android:name="com.google.android.gms.metadata.ModuleDependencies"
            android:enabled="false"
            android:exported="false"
            tools:ignore="MissingClass">
            <intent-filter>
                <action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
            </intent-filter>

            <meta-data android:name="photopicker_activity:0:required" android:value="" />
        </service>

        <!-- Our activity is a subclass of the built-in NativeActivity framework class.
             This will take care of integrating with our NDK code. -->
        <activity
            android:name="com.embarcadero.firemonkey.FMXNativeActivity"
            android:exported="true"
            android:label="MONotify"
            android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode"
            android:launchMode="singleTask">
            <!-- Tell NativeActivity the name of our .so -->
            <meta-data android:name="android.app.lib_name" android:value="MONotify" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name="com.embarcadero.rtl.notifications.NotificationAlarm" />

    </application>
</manifest>
<!-- END_INCLUDE(manifest) -->


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:30 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz