Relay share intents through a headless activity
This commit is contained in:
@@ -27,17 +27,6 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<!-- Share target. Without this filter the app never appears in the
|
||||
system share sheet at all; image/* only, the editor takes photos.
|
||||
Goes on the launcher activity: it is singleTask, so a share
|
||||
re-delivered there replaces its intent (onNewIntent -> setIntent)
|
||||
and the running app picks the photo up without a cold start. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="image/*"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@@ -45,5 +34,19 @@
|
||||
<data android:scheme="exp+recipescamera"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Share target. Without this filter the app never appears in the
|
||||
system share sheet at all; image/* only, the editor takes photos.
|
||||
A separate no-display relay, not MainActivity: a host app that starts
|
||||
the target without FLAG_ACTIVITY_NEW_TASK would otherwise drop the
|
||||
editor into its own task and the share would look like part of it.
|
||||
ShareActivity relaunches MainActivity in our own task instead. -->
|
||||
<activity android:name=".ShareActivity" android:theme="@android:style/Theme.NoDisplay" android:launchMode="standard" android:excludeFromRecents="true" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="image/*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.locphamtran.recipescamera
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
|
||||
/**
|
||||
* Share sheet entry point for SEND / SEND_MULTIPLE.
|
||||
*
|
||||
* A host app that starts us without FLAG_ACTIVITY_NEW_TASK drops the started
|
||||
* activity into its own task, so the editor used to show up as a screen of that
|
||||
* app (it lived in that app's stack, back returned there). MainActivity cannot
|
||||
* fix that itself: bailing out in onCreate would either boot React twice or skip
|
||||
* super.onCreate and crash onDestroy.
|
||||
*
|
||||
* So the share filters live here. This activity never draws (NoDisplay theme):
|
||||
* it hands the same intent to MainActivity with NEW_TASK — singleTask then routes
|
||||
* it to our own task, or re-delivers it to the running instance — and finishes.
|
||||
* The editor is therefore always a task of its own.
|
||||
*/
|
||||
class ShareActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startActivity(
|
||||
Intent(intent)
|
||||
.setClass(this, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user