0
私のアプリの主なテーマは、ユーザーがアプリケーションのボタンをクリックすると、私のアプリからクロームエンジンにウェブサイトを開くことです。私はクリックイベントのコードを実装したときにうまくいきましたが、私のアプリケーションのディープリンクを実装したときには、私が直面している問題でした。深いリンクを持つアプリケーションからクロムのURLを開く方法
私はボタンをクリックしたときに私のアプリは、このようにいくつかのことを示しています。この代わりにユーザーがボタンをクリックすると、ウェブサイトはクロームエンジンで起動する必要があります。私のアプリのMainefestファイルは次のようになり
@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://stackoverflow.com/")));
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/")));
}
});
}
: - - :
私のアプリのMainActivityファイルは次のようになり、私はボタンのクリックイベントにコードを変更した
<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="stackoverflow.com"
android:scheme="http" />
</intent-filter>
</activity>
</application>