如何从具有深度链接的应用中打开 chrome 中的 url

How to open a url in chrome from app having deep linking

我的应用程序的主题是当用户单击应用程序中的按钮时,从我的应用程序打开一个网站到 chrome 引擎。当我为点击事件实现代码时它工作正常,但是当我为我的应用程序实现深度链接时,这些就是我面临的问题。

当我单击按钮时,我的应用程序显示类似这样的内容。而不是当用户点击按钮时,网站必须在 chrome 引擎中启动。

我的应用程序的 MainActivity 文件如下所示:-

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

    button = (Button) findViewById(R.id.button);
    intent = getIntent();
    action = intent.getAction();
    uri = intent.getData();
    if (uri != null) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://whosebug.com/")));
    }
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://whosebug.com/")));
        }
    });
}

我的应用程序的 Mainefest 文件如下所示:-

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
             <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="whosebug.com"
                android:scheme="http" />
        </intent-filter>
    </activity>
</application>

我已经修改了按钮点击事件中的代码,通过 将 chrome 的包名称设置为意图,并且按照我的要求工作正常。

 Intent intent1 = new Intent(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse("http://whosebug.com/"));
            intent1.setPackage("com.android.chrome");
            startActivity(intent1);