Inbound Sharing
Smart WebView can register as a target for Android’s native sharing functionality, allowing users to share content like URLs and text directly to your application from other apps.
How it Works
- Enabling via Manifest: Sharing is enabled via
<intent-filter>
elements for theShareActivity
inAndroidManifest.xml
. These filters specify that the app can handleACTION_SEND
intents fortext/*
andimage/*
MIME types. - User Action: A user in another app (like a browser or social media app) uses the “Share” button and selects your app from the list.
- Activity Launch: Android launches the
ShareActivity
of your app. - Data Handling:
ShareActivity
extracts the shared text or link from the intent. - Redirection: It then constructs a URL based on the main app URL (
ASWV_URL
) and appends the shared content as query parameters. For example:https://your-site.com/?s_uri=SHARED_CONTENT
. - Loading in WebView: Finally, it launches the
MainActivity
and instructs it to load this newly constructed URL, allowing your web application to process the shared content.
Processing on Your Website
Your web application needs to be able to parse the URL query parameters to handle the shared data.
Example JavaScript:
const urlParams = new URLSearchParams(window.location.search);
const sharedContent = urlParams.get('s_uri'); // Matches the key from ShareActivity
if (sharedContent) {
// The content was shared from another app
console.log('Received shared content:', sharedContent);
// Now you can display it, fill a form, etc.
document.getElementById('my-textarea').value = sharedContent;
}
Disabling Sharing
To disable this feature, remove or comment out the entire <activity android:name=".ShareActivity">...</activity>
block from AndroidManifest.xml
.