Skip to content

Android isAvailable method checks Custom Tab support #108

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

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.Color;
import android.provider.Browser;
import androidx.annotation.Nullable;
Expand All @@ -23,6 +24,7 @@
import org.greenrobot.eventbus.Subscribe;

import java.util.regex.Pattern;
import java.util.List;

public class RNInAppBrowser {
private final static String ERROR_CODE = "InAppBrowser";
Expand Down Expand Up @@ -162,6 +164,12 @@ public void close() {
ChromeTabsManagerActivity.createDismissIntent(currentActivity));
}

public void isAvailable(Context context, final Promise promise) {
Intent serviceIntent = new Intent("android.support.customtabs.action.CustomTabsService");
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
promise.resolve(!(resolveInfos == null || resolveInfos.isEmpty()));
}

@Subscribe
public void onEvent(ChromeTabsDismissedEvent event) {
unRegisterEventBus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public void open(final ReadableMap options, final Promise promise) {
public void close() {
inAppBrowser.close();
}

@ReactMethod
public void isAvailable(final Promise promise) {
inAppBrowser.isAvailable(this.reactContext, promise);
}
}
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,7 @@ async function _checkResultAndReturnUrl(
}

async function isAvailable(): Promise<boolean> {
if (Platform.OS === 'android') {
return Promise.resolve(true);
} else {
return RNInAppBrowser.isAvailable();
}
return RNInAppBrowser.isAvailable();
}

export default {
Expand Down