Cannot Click on "Install" for Flickr for Android?

I’m attempting the second challenge at the end of chapter 30, so I modify the WebViewClient to override shouldOverrideUrlLoading: I log the call, then if the scheme is http or https, return false, otherwise create an intent, call startActivity, and return true.

My problem starts immediately, when I try to log the call before actually doing anything. When I click on an http/https link, no problem, I get a log message. But clicking on the “Install” button gives me nothing.

Now, if I don’t modify the WebViewClient, I get the expected error message about “market://…” when I click “Install”, so the button is clickable in the WebView.

Am I missing something obvious here?


StartActivity crashes in the following code. If the scheme is “http” or “https”, everything works fine, but when I click a link whose scheme is “market”, application crashes. The following code is called from public boolean shouldOverrideUrlLoading(WebView view, String url)

    if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {         
        return false;
    } else {
        final Intent i = new Intent(Intent.ACTION_VIEW, uri);
        return true;

Hi, I face problems when I work with this challenge. After sometimes, I found the solution in stackoverflow
I would like to share it with you:

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

 * Created by behin on 12/3/2017.

public class PhotoPageFragment extends VisibleFragment {
	private static final String ARG_URI = "photo_page_url";

	private Uri mUri;
	private WebView mWebView;
	private ProgressBar mProgressBar;

	public static PhotoPageFragment newInstance(Uri uri) {
		Bundle args = new Bundle();
		args.putParcelable(ARG_URI, uri);

		PhotoPageFragment fragment = new PhotoPageFragment();
		return fragment;

	public void onCreate(@Nullable Bundle savedInstanceState) {

		mUri = getArguments().getParcelable(ARG_URI);

	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_photo_page, container, false);

		mProgressBar = (ProgressBar) v.findViewById(;
		mProgressBar.setMax(100); // WebChromeClient reports in range 0-100

		mWebView = (WebView) v.findViewById(;
		mWebView.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView webView, int newProgress) {
				if (newProgress == 100) {
				} else {

			public void onReceivedTitle(WebView webView, String title) {
				AppCompatActivity activity = (AppCompatActivity) getActivity();
		mWebView.setWebViewClient( new photoPageWebViewClient());

		return v;

	private class photoPageWebViewClient extends WebViewClient {
		@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
		public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
			String uriString = request.getUrl().toString();

			// is this a play store URL?
			String partialUrl = "/store/apps/details?id=";

			if (uriString.contains(partialUrl)) {
				// extract the app id from the URL
				int pos = uriString.indexOf(partialUrl) + partialUrl.length();
				String appId = uriString.substring(pos);

				try {
					// open the google play app
					Intent intent = new Intent(Intent.ACTION_VIEW);
					intent.setData(Uri.parse("market://details?id=" + appId));
					return true;  // we overrode the url load

				} catch (ActivityNotFoundException e) {
					// no google play app, load URL in device browser
					Intent intent = new Intent(Intent.ACTION_VIEW);
					intent.setData(Uri.parse("" + appId));
					return true;

			return false;  // no override, let the webview load this url

		public boolean webViewCanGoBack() {
		return mWebView != null && mWebView.canGoBack();

	public void webViewGoBack() {
		if (mWebView != null) {