Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android navigation component open url

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?

like image 452
antanas_sepikas Avatar asked Aug 06 '18 09:08

antanas_sepikas


2 Answers

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"/>
like image 134
antanas_sepikas Avatar answered Sep 19 '22 01:09

antanas_sepikas


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.

like image 33
Rahul Mishra Avatar answered Sep 18 '22 01:09

Rahul Mishra