diff --git a/.circleci/config.yml b/.circleci/config.yml index d718b52fc..9541943c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -177,9 +177,10 @@ jobs: path: ios/RocketChatRN.ipa - persist_to_workspace: - root: ios + root: . paths: - - RocketChatRN.ipa + - ios/*.ipa + - ios/fastlane/report.xml ios-testflight: macos: diff --git a/android/app/src/main/java/com/rocketchatrn/CustomTabsAndroid.java b/android/app/src/main/java/com/rocketchatrn/CustomTabsAndroid.java index d365fbaab..605a058ed 100644 --- a/android/app/src/main/java/com/rocketchatrn/CustomTabsAndroid.java +++ b/android/app/src/main/java/com/rocketchatrn/CustomTabsAndroid.java @@ -1,13 +1,18 @@ package com.rocketchatrn; +import android.content.Intent; +import android.content.pm.ResolveInfo; import android.net.Uri; import android.support.customtabs.CustomTabsIntent; - +import android.widget.Toast; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import java.util.List; + +import chat.rocket.reactnative.R; /** * Launches custom tabs. @@ -15,12 +20,9 @@ import com.facebook.react.bridge.ReactMethod; public class CustomTabsAndroid extends ReactContextBaseJavaModule { - public ReactApplicationContext context; - public CustomTabsAndroid(ReactApplicationContext reactContext) { super(reactContext); - this.context = reactContext; } @Override @@ -32,6 +34,23 @@ public class CustomTabsAndroid extends ReactContextBaseJavaModule { public void openURL(String url) throws NullPointerException { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(getReactApplicationContext().getCurrentActivity(), Uri.parse(url)); + + if (CustomTabsHelper.isChromeCustomTabsSupported(getReactApplicationContext())) { + customTabsIntent.launchUrl(getReactApplicationContext().getCurrentActivity(), Uri.parse(url)); + } else { + //open in browser + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + //ensure browser is present + final List customTabsApps = getReactApplicationContext() + .getCurrentActivity().getPackageManager().queryIntentActivities(i, 0); + + if (customTabsApps.size() > 0) { + getReactApplicationContext().startActivity(i); + } else { + // no browser + Toast.makeText(getReactApplicationContext(), R.string.no_browser_found, Toast.LENGTH_SHORT).show(); + } + } } } diff --git a/android/app/src/main/java/com/rocketchatrn/CustomTabsHelper.java b/android/app/src/main/java/com/rocketchatrn/CustomTabsHelper.java new file mode 100644 index 000000000..99934ec33 --- /dev/null +++ b/android/app/src/main/java/com/rocketchatrn/CustomTabsHelper.java @@ -0,0 +1,24 @@ +package com.rocketchatrn; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; + +import java.util.List; + +/** + * Contains helper methods for custom tabs. + */ + +public class CustomTabsHelper { + + private static final String SERVICE_ACTION = "android.support.customtabs.action.CustomTabsService"; + private static final String CHROME_PACKAGE = "com.android.chrome"; + + public static boolean isChromeCustomTabsSupported(final Context context) { + Intent serviceIntent = new Intent(SERVICE_ACTION); + serviceIntent.setPackage(CHROME_PACKAGE); + List resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0); + return !(resolveInfos == null || resolveInfos.isEmpty()); + } +} diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 758ba54dd..23925e195 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ RocketChatRN + + No Browser Found