Android Deep Link仅打开一个应用程序实例吗?

问题描述 投票:0回答:1

关闭应用程序后,深层链接可以正常工作。但是,如果该应用程序已经打开,则Deeplink只会打开该应用程序,而不是打开该链接。

MainActivity.java文件:

public class MainActivity extends Activity{
    private ProgressBar progressBar;
    private WebView webView;
    private SwipeRefreshLayout mySwipeRefreshLayout;
    private boolean mShouldPause;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        progressBar.setMax(100);
        webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClientDemo());
        webView.setWebChromeClient(new WebChromeClientDemo());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.clearCache(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);

        mySwipeRefreshLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipeContainer);


        mySwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        webView.reload();
                        mySwipeRefreshLayout.setRefreshing(false);
                    }
                }
        );



    private class WebViewClientDemo extends WebViewClient {



        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            progressBar.setProgress(100);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
        }
    }


    private class WebChromeClientDemo extends WebChromeClient {

        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress);
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        else {
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }

    @Override
    // This method is used to detect back button
    public void onBackPressed() {
        if (this.webView.canGoBack()) {
            this.webView.goBack();
            return;
        }

        else {
            // Let the system handle the back button
           super.onBackPressed();
        }
    }

}

假设我通过电报打开了应用链接(当应用未运行时),它可以完美打开。但是,当应用程序在后台运行时,然后单击Telegram中的应用程序链接时,它只是打开应用程序,而不是打开该特定链接。

android android-studio deep-linking
1个回答
0
投票

[当应用程序在背景或前景上运行时。针对您的情况:

  • 在活动清单中添加应用启动模式singleTop
  • 在您的活动句柄中,打开onNewintent(Intent)中的链接网址
    protected void onNewIntent(Intent intent) {
       super.onNewIntent(intent);
       Uri uri = intent.getData();
       if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
           //open the link here
       }
    }

© www.soinside.com 2019 - 2024. All rights reserved.