From cda2b34a4e7dfec330e12889ca41ae65f8088ef6 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 23 Jan 2019 01:19:46 -0700 Subject: [PATCH 1/5] Add ability to override inferred MIME type when launching intent --- .../host/exp/exponent/modules/api/IntentLauncherModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/IntentLauncherModule.java b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/IntentLauncherModule.java index 643a9be087efc..42093599203b8 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/IntentLauncherModule.java +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/IntentLauncherModule.java @@ -29,7 +29,7 @@ public String getName() { @ReactMethod - public void startActivity(String activity, @Nullable ReadableMap data, @Nullable String uri, Promise promise) { + public void startActivity(String activity, @Nullable ReadableMap data, @Nullable String uri, @Nullable String mime, Promise promise) { if (pendingPromise != null) { pendingPromise.reject("ERR_INTERRUPTED", "A new activity was started"); pendingPromise = null; @@ -49,7 +49,7 @@ public void startActivity(String activity, @Nullable ReadableMap data, @Nullable } if (uri != null && !uri.isEmpty()) { - intent.setData(Uri.parse(uri)); + intent.setDataAndType(Uri.parse(uri), mime); } if (currentActivity != null) { From 9e6daadefdc54a9f1fa341ce72bcabd95fc24b30 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 23 Jan 2019 12:56:14 -0700 Subject: [PATCH 2/5] Accept MIME as optional argument in startActivityAsync --- .../expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts b/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts index a27bfcdafc773..ceded9a1b7970 100644 --- a/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts +++ b/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts @@ -105,10 +105,11 @@ export function startActivityAsync( activity: string, // TODO: Make this type more precise data: { [key: string]: any } | null = null, - uri: string | null = null + uri: string | null = null, + mime: string | null = null ): Promise { if (!ExponentIntentLauncher.startActivity) { throw new UnavailabilityError('IntentLauncherAndroid', 'startActivityAsync'); } - return ExponentIntentLauncher.startActivity(activity, data, uri); + return ExponentIntentLauncher.startActivity(activity, data, uri, mime); } From dd8e6c60422ef3818574a8fbb06c91a5b9f1b393 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 23 Jan 2019 13:42:35 -0700 Subject: [PATCH 3/5] Add documentation to reflect new startActivityAsync parameters. --- docs/versions/unversioned/sdk/intent-launcher.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/versions/unversioned/sdk/intent-launcher.md b/docs/versions/unversioned/sdk/intent-launcher.md index 2f4aa64021f03..3bf84a1247f76 100644 --- a/docs/versions/unversioned/sdk/intent-launcher.md +++ b/docs/versions/unversioned/sdk/intent-launcher.md @@ -6,11 +6,19 @@ Provides a way to launch android intents. e.g. - opening a specific settings scr ## Usage -### `Expo.IntentLauncherAndroid.startActivityAsync(activity, data)` +### `Expo.IntentLauncherAndroid.startActivityAsync(activity, data, uri, mime)` -Starts the specified activity. The optional `data` parameter can be specified to pass additional data object to the activity. The method will return a promise which resolves when the user returns to the app. +Starts the specified activity. The method will return a promise which resolves when the user returns to the app. -There are a few pre-defined constants you can use for the `activity` parameter. You can find them at [expo/expo-sdk/src/IntentLauncherAndroid.js](https://github.com/expo/expo-sdk/blob/master/src/IntentLauncherAndroid.js). +#### Arguments + +- **activity (_string_)** -- A string specifying which settings screen to open, or alternatively the action of the intent. There are a few pre-defined constants you can use for this parameter. You can find them at [expo/expo/src/IntentLauncherAndroid.js](https://github.com/expo/expo/blob/master/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts). + +- **data (_{ [key: string]: any }_)** (Optional) -- A map specifying additional key-value pairs which are passed with the intent as `extras`. + +- **uri (_string_)** (Optional) -- A URI specifying the data that the intent should operate upon. (_Note: Android requires the URI scheme to be lowercase, unlike the formal RFC._) + +- **mime (_string_)** (Optional) -- A string specifying the MIME type of the data represented by the `uri` argument. Ignore this argument to allow Android to infer the correct MIME type. #### Example From 5bc031cceabc5125004f9479bde58cdc4e65c832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Fri, 25 Jan 2019 02:33:20 -0700 Subject: [PATCH 4/5] Use backticks for styling TS types in docs Co-Authored-By: rhunt4675 --- docs/versions/unversioned/sdk/intent-launcher.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/versions/unversioned/sdk/intent-launcher.md b/docs/versions/unversioned/sdk/intent-launcher.md index 3bf84a1247f76..7adf1b868332b 100644 --- a/docs/versions/unversioned/sdk/intent-launcher.md +++ b/docs/versions/unversioned/sdk/intent-launcher.md @@ -12,13 +12,13 @@ Starts the specified activity. The method will return a promise which resolves w #### Arguments -- **activity (_string_)** -- A string specifying which settings screen to open, or alternatively the action of the intent. There are a few pre-defined constants you can use for this parameter. You can find them at [expo/expo/src/IntentLauncherAndroid.js](https://github.com/expo/expo/blob/master/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts). +- **activity (`string`)** -- A string specifying which settings screen to open, or alternatively the action of the intent. There are a few pre-defined constants you can use for this parameter. You can find them at [expo/src/IntentLauncherAndroid.ts](https://github.com/expo/expo/blob/master/packages/expo/src/IntentLauncherAndroid/IntentLauncherAndroid.ts). -- **data (_{ [key: string]: any }_)** (Optional) -- A map specifying additional key-value pairs which are passed with the intent as `extras`. +- **data (`{ [key: string]: any }`)** (Optional) -- A map specifying additional key-value pairs which are passed with the intent as `extras`. -- **uri (_string_)** (Optional) -- A URI specifying the data that the intent should operate upon. (_Note: Android requires the URI scheme to be lowercase, unlike the formal RFC._) +- **uri (`string`)** (Optional) -- A URI specifying the data that the intent should operate upon. (_Note: Android requires the URI scheme to be lowercase, unlike the formal RFC._) -- **mime (_string_)** (Optional) -- A string specifying the MIME type of the data represented by the `uri` argument. Ignore this argument to allow Android to infer the correct MIME type. +- **mime (`string`)** (Optional) -- A string specifying the MIME type of the data represented by the `uri` argument. Ignore this argument to allow Android to infer the correct MIME type. #### Example From aa543a7c578ba22ff5ef9f4c173aef7fe20b144e Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Fri, 25 Jan 2019 03:01:55 -0700 Subject: [PATCH 5/5] Changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 741d53531c8bc..0cfcc5fe6dec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This is the log of notable changes to the Expo client that are developer-facing. ### 🎉 New features +- added support for overriding MIME type in `IntentLauncherAndroid.startActivityAsync` for Android by [@rhunt4675](https://github.com/rhunt4675) ([#3300](https://github.com/expo/expo/pull/3300)) + ### 🐛 Bug fixes - fix `ImagePicker.launchImageLibraryAsync` and `ImageManipulator.manipulateAsync` in SDKs lower than 32 [@bbarthec](https://github.com/bbarthec) ([#3159](https://github.com/expo/expo/pull/3159))