1

I have created an app using the WebView application which shows the web site of my blog, I'm in your blog using links to Google Play, but I can not make so that all links to Google Play opened right on the very Play Market, now all links open in the app not even forwarded to the browser. What codes should I use to do so? please help

These are the codes I use in MainActivity.java:

package com.thegosa.bterwe;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView; // import WebView class
import android.webkit.WebViewClient; // import class WebViewClient
import android.widget.ProgressBar;
import android.widget.Toast;



@SuppressWarnings("ALL")
public class MainActivity extends AppCompatActivity {


    WebView wv ;
    private Bundle savedInstanceState;

    // When Back Pressed Go Back.
    @Override
    public void onBackPressed(){
        if (wv.canGoBack()){
            wv.goBack();
        }else {
            super.onBackPressed();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        wv = (WebView) findViewById(R.id.webView) ;
        //Enable JavaScript
        wv.getSettings().setJavaScriptEnabled(true);
        wv.setFocusable(true);
        wv.setFocusableInTouchMode(true);
        // Set Render Priority To High
        wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        wv.getSettings().setDomStorageEnabled(true);
        wv.getSettings().setDatabaseEnabled(true);
        wv.getSettings().setAppCacheEnabled(true);
        wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        //Load Url
        wv.loadUrl("http://themesxperia.blogspot.com/");
        wv.setWebViewClient(new WebViewClient());



    }




}
Suhrab
  • 31
  • 5
  • Should be helpful: > http://stackoverflow.com/questions/11753000/how-to-open-the-google-play-store-directly-from-my-android-application – ndelanou Apr 05 '17 at 15:58
  • Try commenting this line wv.setWebViewClient(new WebViewClient()); and clearing out the preferences for this package from application manager. – Anurag Singh Apr 05 '17 at 15:59

2 Answers2

1

You should use an Intent to the google Play Market instead of a webview.

Here is the solution:

How to open the Google Play Store directly from my Android application?

Community
  • 1
  • 1
ndelanou
  • 523
  • 5
  • 16
1
public void OpenPlayStore() {
            Uri uri = Uri.parse(getResources().getString(R.string.rate_us));
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(getResources().getString(R.string.rate_us2))));
            }
        }

This will open Play Market, if it's not possible it will open browser on your app website.

Where strings are:

rate_us is "market://details?id=com.companyname.appname"

rate_us2 is link to your app in Play Store

Hope it helps.