简体   繁体   中英

How to redirect links to Google Play Market?

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()); } } 

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM