Skip to content

Commit

Permalink
Merge pull request #108 from eljass/feat-deeplink
Browse files Browse the repository at this point in the history
feat(android): handle opening deeplinks inside webview
  • Loading branch information
riderx authored Mar 20, 2024
2 parents 594697c + a182cc4 commit 7bb1625
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -326,6 +329,19 @@ public boolean shouldOverrideUrlLoading(
WebView view,
WebResourceRequest request
) {
Context context = view.getContext();
String url = request.getUrl().toString();

if (!url.startsWith("https://") && !url.startsWith("http://")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Do nothing
}
}
return false;
}

Expand Down

0 comments on commit 7bb1625

Please sign in to comment.