'How to pass safe args as bundle in android explicit deep link?

I am creating an explicit deep link in navigation component using safe args.

PendingIntent pendingIntent = new NavDeepLinkBuilder(getApplicationContext())
                .setGraph(R.navigation.mobile_navigation)
                .setDestination(R.id.nav_order_details)
                .setArguments(//TODO pass bundle)
                .setComponentName(MainActivity.class)
                .createPendingIntent();

The problem is I need to pass a bundle in arguments but I dont know how to convert Safe args to bundle in java.

I found this format in kotlin

OrderDetailsFragmentArgs(id).toBundle()

I need to convert it into java code. Please help.



Solution 1:[1]

I finally solved it by using this code

Bundle bundle = new Bundle();
bundle.putString("orderId", id);

OrderDetailsFragmentArgs args = OrderDetailsFragmentArgs.fromBundle(bundle);

PendingIntent intent = new NavDeepLinkBuilder(getApplicationContext())
                    .setGraph(R.navigation.mobile_navigation)
                    .setDestination(R.id.nav_order_details)
                    .setArguments(args.toBundle())
                    .setComponentName(MainActivity.class)
                    .createPendingIntent();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ankit Verma