Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Add ability to override inferred MIME type when launching Intent #3300

Merged
merged 6 commits into from Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
14 changes: 11 additions & 3 deletions docs/versions/unversioned/sdk/intent-launcher.md
Expand Up @@ -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).
rhunt4675 marked this conversation as resolved.
Show resolved Hide resolved

- **data (_{ [key: string]: any }_)** (Optional) -- A map specifying additional key-value pairs which are passed with the intent as `extras`.
rhunt4675 marked this conversation as resolved.
Show resolved Hide resolved

- **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._)
rhunt4675 marked this conversation as resolved.
Show resolved Hide resolved

- **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.
rhunt4675 marked this conversation as resolved.
Show resolved Hide resolved

#### Example

Expand Down
Expand Up @@ -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<boolean> {
if (!ExponentIntentLauncher.startActivity) {
throw new UnavailabilityError('IntentLauncherAndroid', 'startActivityAsync');
}
return ExponentIntentLauncher.startActivity(activity, data, uri);
return ExponentIntentLauncher.startActivity(activity, data, uri, mime);
}