Skip to content

Instantly share code, notes, and snippets.

@GVRV
Created June 16, 2016 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GVRV/5879fcf0b1838b495e3a2151449e0da3 to your computer and use it in GitHub Desktop.
Save GVRV/5879fcf0b1838b495e3a2151449e0da3 to your computer and use it in GitHub Desktop.
<data
android:host="example.com"
android:pathPrefix="/app/"
android:scheme="https" />
<data
android:host="example.com"
android:pathPrefix="/app/"
android:scheme="http" />
private void handleUrlAction(final URLAction urlAction){
Connect.getInstance().getProductManager().getProductsWithQuery(urlAction.productQuery(), new ConnectCallback() {
@Override
public void onSuccess(Object object) {
final ProductResponse productResponse = (ProductResponse) object;
if (productResponse.isSuccessful())
mainActivityNavigationManager.navigateDownToProductList(urlAction.productQuery());
else browseURLActionWithoutApp(urlAction);
}
@Override
public void onFailure(Throwable throwable, String errorMessage) {
browseURLActionWithoutApp(urlAction);
}
@Override
public boolean isCallbackStillVisible() {
return !isDestroyed;
}
});
}
private void browseURLActionWithoutApp(URLAction urlAction){
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> list = packageManager.queryIntentActivities(new Intent(Intent.ACTION_VIEW, urlAction.originUri), PackageManager.MATCH_DEFAULT_ONLY);
final List<Intent> urlViewIntents = new ArrayList<>();
if (list.size()==1 && list.get(0).activityInfo.packageName.equals(getPackageName())) {
showDialogForSettings(); // here we ask user to go to settings and clear defaults - terrible UX!
return;
}
for (ResolveInfo resolveInfo : list) {
final String p = resolveInfo.activityInfo.packageName;
if (!p.equals(getPackageName())){
final Intent intent = new Intent(Intent.ACTION_VIEW, urlAction.originUri);
intent.setPackage(p);
urlViewIntents.add(intent);
}
}
if (urlViewIntents.size() != 0){
Intent chooserIntent = Intent.createChooser(urlViewIntents.remove(0), getString(R.string.choose_browser));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, urlViewIntents.toArray(new Parcelable[urlViewIntents.size()]));
startActivity(chooserIntent);
}else {
showAlert(getString(R.string.error), getString(R.string.could_not_open_link), getString(R.string.dismiss)); // here we show user alert that they don't have app installed to open ilnk
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment