Skip to content

Instantly share code, notes, and snippets.

@achorein
Last active August 26, 2023 14:46
Show Gist options
  • Save achorein/d7a2c84a0b140afc699a90494131ced1 to your computer and use it in GitHub Desktop.
Save achorein/d7a2c84a0b140afc699a90494131ced1 to your computer and use it in GitHub Desktop.
Expo React Native (Expo SDK 46) : Share Intent, auto configuration for Android using https://github.com/ajith-ab/react-native-receive-sharing-intent
--- android/app/build.gradle 2022-10-29 11:38:29.000000000 +0200
+++ share-extension/android/app/build.gradle 2022-10-29 11:12:16.000000000 +0200
@@ -339,6 +339,8 @@
} else {
implementation jscFlavor
}
+
+ implementation project(':reactnativereceivesharingintent')
}
if (isNewArchitectureEnabled()) {
--- android/settings.gradle 2022-10-29 11:38:29.000000000 +0200
+++ share-extension/android/settings.gradle 2022-10-29 11:12:16.000000000 +0200
@@ -15,3 +15,6 @@
include(":ReactAndroid:hermes-engine")
project(":ReactAndroid:hermes-engine").projectDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../ReactAndroid/hermes-engine");
}
+
+include ':reactnativereceivesharingintent'
+project(':reactnativereceivesharingintent').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-receive-sharing-intent/android')
--- android/app/src/main/java/com/example/exposhareintentdemo/MainActivity.java 2022-10-29 11:54:18.000000000 +0200
+++ share-extension/android/app/src/main/java/com/example/exposhareintentdemo/MainActivity.java 2022-10-29 11:12:16.000000000 +0200
@@ -2,6 +2,7 @@
import android.os.Build;
import android.os.Bundle;
+import android.content.Intent;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
@@ -80,4 +81,10 @@
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
}
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ setIntent(intent);
+ }
}
--- android/app/src/main/AndroidManifest.xml 2022-10-29 11:54:18.000000000 +0200
+++ share-extension/android/app/src/main/AndroidManifest.xml 2022-10-29 11:12:16.000000000 +0200
@@ -21,8 +21,16 @@
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="46.0.0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
- <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/xxx-xxx-xxx-xxx-xxx"/>
- <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustPan" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
+ <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/xxx-xxx-xxx-xxx-xxx"/>
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
+ android:launchMode="singleTask"
+ android:windowSoftInputMode="adjustResize"
+ android:theme="@style/Theme.App.SplashScreen"
+ android:exported="true"
+ android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
@achorein
Copy link
Author

achorein commented Aug 26, 2023

and share intent (app.json)

android: {
      intentFilters: [
        {
          action: 'SEND',
          category: 'DEFAULT',
          data: [
            {
              mimeType: 'text/*',
            },
          ],
        },
      ],
    },

and kotlin 1.6 (app.json):

plugins: [
  [
    'expo-build-properties',
    {
      android: {
        kotlinVersion: '1.6.10',
      },
    },
  ],
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment