I have simple code that opens URL in a browser:
startActivity(Intent(
Intent.ACTION_VIEW, Uri.parse(resources.getString(R.string.application_url))
))
How can I convert this to the navigation component item?
Do I need to build custom navigator for this, or navigation component has something built in for such case?
I figured it out, for this simple case custom navigator is not needed all you need is to create navigation endpoint:
<activity
android:id="@+id/navigation_endpoint_id"
app:action="android.intent.action.VIEW"
app:data="@string/application_url"/>
For Dynamic Uri, we can pass the data like this:
<activity
android:id="@+id/whatsappRedirectionActivity"
app:action="android.intent.action.VIEW"
app:dataPattern="https://wa.me/{number}">
<argument
android:name="number"
app:argType="string" />
</activity>
This needs to include to navigation graph where you want to redirection. Using this we can use safeargs actions as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With