Reputation: 1219
The main theme of my app is to open a website from my app into the chrome engine when user clicks on the button in the app. When i have implemented the code for click event it working fine, but when i have implemented the deep linking for my app, these was an that issue i'm facing.
My App is showing some thing like this when i click on the button. Instead of this when user clicks on the button the website has to launch in chrome engine.
The MainActivity file of my app look like:-
@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/")));
}
});
}
The Mainefest file of my app look like:-
<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>
Upvotes: 0
Views: 1040
Reputation: 1219
I have modified the code in the button click event, by setting package name of the chrome to the intent, and working fine as per my requirement.
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse("http://stackoverflow.com/"));
intent1.setPackage("com.android.chrome");
startActivity(intent1);
Upvotes: 1