Android (Manifest) – open intent in app in background instead of in sender

  

I managed to edit my manifest file so that my Android app can receive files with a specific file extension from messaging apps via intents:

<intent-filter>
<!– needed for properly formatted email messages –>
<data
android:scheme=”content”
android:mimeType=”application/vnd.eureka”
android:pathPattern=”.*\\.cw” />
<!– needed for mangled email messages –>
<data
android:scheme=”content”
android:mimeType=”application/eureka”
android:pathPattern=”.*\\.cw” />
<!– needed for mangled email messages –>
<data
android:scheme=”content”
android:mimeType=”application/octet-stream”
android:pathPattern=”.*\\.cw” />
<data
android:scheme=”content”
android:mimeType=”*/*”
android:pathPattern=”.*\\.cw” />

<action android:name=”android.intent.action.VIEW” />

<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.BROWSABLE” />
</intent-filter>

<!– Register to handle file opening –>
<intent-filter>
<data android:scheme=”file”
android:mimeType=”*/*”
android:pathPattern=”.*\\.cw”
android:host=”*”/>

<action android:name=”android.intent.action.VIEW” />

<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.BROWSABLE” />
</intent-filter>

This works well when my app is not running before it is supposed to receive the file or when the intent is coming from WhatsApp or the GMail app.

However, when the app is already running in the background and you try to open a file with it from Telegram messenger, a second instance of the app is created seemingly inside Telegram (the app switcher shows two instances of the app: one labeled “Eureka”/the name of the app and one labeled Telegram). This causes the app to stop responding. It even happens with new projects, so I suspect Delphi apps do not support having multiple instances (I am developing in Delphi 10 Seattle).

I would like the intent to be opened in the instance already running in the background to avoid this problem.

LaunchMode is already set to “singleTask” and I changed it to “singleInstance” without success.

Comments are closed.