Skip to content

Commit

Permalink
Update MainActivity.java
Browse files Browse the repository at this point in the history
redirect not ivelt links to browser
  • Loading branch information
KFMDMSolutions committed Jul 19, 2021
1 parent dd5daba commit a1df7ff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/android/cts/ivelt/MainActivity.java
Expand Up @@ -404,11 +404,11 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
|| url.startsWith("https://www.dropbox.com/")) {
return false;

} else {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}


// reject anything other
return true;
}

@Override
Expand Down

5 comments on commit a1df7ff

@bevekashaivelt
Copy link
Collaborator

@bevekashaivelt bevekashaivelt commented on a1df7ff Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will cause phones without browsers to crash.

use this instead

Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            try {
                startActivity(i);
            }catch (ActivityNotFoundException activityNotFoundException){
                if (
                        url.startsWith("https://drive.google.com/") ||
                                url.startsWith("https://accounts.google.com/") ||
                                url.startsWith("https://www.yiddish24.com/") ||
                                url.startsWith("https://www.dropbox.com/")) {
                    return false;
                }else{
                    Toast.makeText(MainActivity.this,"לינק געבלאקט, אשריכם ישראל" ,Toast.LENGTH_LONG).show();
                }
            }
            return true;

@bevekashaivelt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code I posted will try to open the links in the appropriate app, if it fails it goes to the browser, and then comes back to our app to open it. If it won't open it due to not having a browser and not being in the whitelist, it shows a toast message saying that the link was blocked.

@KFMDMSolutions
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code I posted will try to open the links in the appropriate app, if it fails it goes to the browser, and then comes back to our app to open it. If it won't open it due to not having a browser and not being in the whitelist, it shows a toast message saying that the link was blocked.

just for clarity uri.Parse is lowercase

@bevekashaivelt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I am using the newer version of webview that uses WebResourceRequest which already includes the url as a URI, so i just rewrote that script a bit, however the rest of the code was tested.

@KFMDMSolutions
Copy link
Owner Author

@KFMDMSolutions KFMDMSolutions commented on a1df7ff Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I am using the newer version of webview that uses WebResourceRequest which already includes the url as a URI, so i just rewrote that script a bit, however the rest of the code was tested.

just tested it on a android 4.4
and it still crashes

ok on android 6 it works

Please sign in to comment.