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.
This commit is contained in:
parent
89c178470a
commit
1df96aef91
|
@ -177,9 +177,10 @@ jobs:
|
||||||
path: ios/RocketChatRN.ipa
|
path: ios/RocketChatRN.ipa
|
||||||
|
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
root: ios
|
root: .
|
||||||
paths:
|
paths:
|
||||||
- RocketChatRN.ipa
|
- ios/*.ipa
|
||||||
|
- ios/fastlane/report.xml
|
||||||
|
|
||||||
ios-testflight:
|
ios-testflight:
|
||||||
macos:
|
macos:
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package com.rocketchatrn;
|
package com.rocketchatrn;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.customtabs.CustomTabsIntent;
|
import android.support.customtabs.CustomTabsIntent;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import chat.rocket.reactnative.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launches custom tabs.
|
* Launches custom tabs.
|
||||||
|
@ -15,12 +20,9 @@ import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
public class CustomTabsAndroid extends ReactContextBaseJavaModule {
|
public class CustomTabsAndroid extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
public ReactApplicationContext context;
|
|
||||||
|
|
||||||
|
|
||||||
public CustomTabsAndroid(ReactApplicationContext reactContext) {
|
public CustomTabsAndroid(ReactApplicationContext reactContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
this.context = reactContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +34,23 @@ public class CustomTabsAndroid extends ReactContextBaseJavaModule {
|
||||||
public void openURL(String url) throws NullPointerException {
|
public void openURL(String url) throws NullPointerException {
|
||||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||||
CustomTabsIntent customTabsIntent = builder.build();
|
CustomTabsIntent customTabsIntent = builder.build();
|
||||||
|
|
||||||
|
if (CustomTabsHelper.isChromeCustomTabsSupported(getReactApplicationContext())) {
|
||||||
customTabsIntent.launchUrl(getReactApplicationContext().getCurrentActivity(), Uri.parse(url));
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
|
||||||
|
return !(resolveInfos == null || resolveInfos.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">RocketChatRN</string>
|
<string name="app_name">RocketChatRN</string>
|
||||||
|
|
||||||
|
<string name="no_browser_found">No Browser Found</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue