Skip to content
Snippets Groups Projects
Commit 1df96aef authored by Saket Kumar's avatar Saket Kumar Committed by Guilherme Gazzo
Browse files

Handle when custom tabs and browser is not installed on the device. (#172)

* Handle when custom tabs and browser is not installed on the device.
parent 89c17847
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
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<ResolveInfo> 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();
}
}
}
}
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<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
return !(resolveInfos == null || resolveInfos.isEmpty());
}
}
<resources>
<string name="app_name">RocketChatRN</string>
<string name="no_browser_found">No Browser Found</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment