如何设置Chrome自定义标签回退到WebView?

时间:2017-08-16 18:06:30

标签: android google-chrome webview

我想将Webview设置为chrome自定义标签的后备。如果用户的移动设备上没有安装chrome,我希望Webview在应用中打开网址。

public class Main3Activity extends AppCompatActivity {
    static final String SITE_URL = "http://secure.shopershop.in/amazon-mobile-accessories";
    static final String SITE_URL1 = "http://secure.shopershop.in/flipkart-mobile-accessories";
    CustomTabsIntent customTabsIntent;
    CustomTabsIntent.Builder intentBuilder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        setTitle("Mobile Accessories");
        intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
        intentBuilder.setExitAnimations(this, R.anim.right_to_left_end, R.anim.left_to_right_end);
        intentBuilder.setStartAnimations(this, R.anim.left_to_right_start, R.anim.right_to_left_start);
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));

        customTabsIntent = intentBuilder.build();
        intentBuilder.addDefaultShareMenuItem();
        intentBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(
                getResources(), R.drawable.ic_arrow_back_black_24dp));
    }

    public void performAction(View arg0) {
        customTabsIntent.launchUrl(this, Uri.parse(SITE_URL));
    }

    public void performAction1 (View arg0) {
        customTabsIntent.launchUrl(this, Uri.parse(SITE_URL1));
    }
}

0 个答案:

没有答案