How to set fallback of Chrome Custom tab to WebView?

故事扮演 提交于 2019-12-13 07:26:51

问题


I want to set Webview as fallback of chrome custom tab. If user don't have chrome installed on their mobile I want Webview to open url in the app.

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

来源:https://stackoverflow.com/questions/45720315/how-to-set-fallback-of-chrome-custom-tab-to-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!