Make your Android app a share goal. Obtain easy information from different purposes with Hilt and Compose | by Nikita Grishko | Jan, 2023 | Zombie Tech

PROJECT NEWS  > News >  Make your Android app a share goal. Obtain easy information from different purposes with Hilt and Compose | by Nikita Grishko | Jan, 2023 | Zombie Tech
| | 0 Comments

roughly Make your Android app a share goal. Obtain easy information from different purposes with Hilt and Compose | by Nikita Grishko | Jan, 2023 will lid the most recent and most present counsel approaching the world. door slowly subsequently you perceive with ease and accurately. will addition your data proficiently and reliably

To raised perceive the sharing performance, let’s outline its use case. For instance, in case you are creating a social networking utility, you may need to present the flexibility to share textual content or pictures. In actual fact, there are various extra purposes for this performance. Nearly all messaging apps, social networks, and even easy note-taking apps use this function.

For a non-compositing app, there is a fairly simple information within the official Android documentation, however I’ve discovered that this is not fairly the identical for compositing apps. So let’s go and discover ways to do that step-by-step.

First, let’s focus on what applied sciences and libraries we are going to use. To maintain this text easy, I am assuming most of you might be acquainted with Compose and all different trendy instruments. If not, I extremely advocate checking them out.

  1. Jetpack Compose is our UI toolkit.
  2. Compose navigation to navigate between composables whereas profiting from the infrastructure and options of the navigation part.
  3. Hilt is our DI framework. Right here it is usually vital to know learn how to combine Hilt with Jetpack Compose

On this listing, the Hilt is an non-compulsory part, however it should make your life rather a lot simpler, so I like to recommend utilizing it.

Photograph by Myriam Jessier on Unsplash

First let’s replace our manifest. To mark our utility as a shared purpose, we should specify <intent-filter> part for our Exercise.

By specifying the intent filter part for our exercise, we let the system know that we’re able to course of the intent with the desired parameters.

So in our case these parameters might be:

<motion android:title="android.intent.motion.SEND" />

That is the default motion used to share some information.

<information android:mimeType="textual content/*" />

Right here we let the system know that we will course of any textual content information.

<information android:mimeType="picture/*" />

And that is serving to obtain a picture.

For a extra detailed description, learn the official information.

If you are going to launch your app proper at times share one thing, your app ought to seem in Android’s share sheet.

Now’s the time to replace our navigation graph, since we most likely need to present a particular display screen that may course of shared information.

Your navigation graph ought to appear like this:

Fairly easy, proper? Identical to for normal deep hyperlinks, we specify the listing of navDeepLink . however as a substitute of uriPattern we’re specifying motion Y mimeType that correspond to our intent filter within the manifest. The following query is how can I entry the shared information? Let’s look.

And naturally, let’s inject our ViewModel into Composable:

Our Intent is now accessible to our ViewModel through SavedStateHandle with none extra work. To entry it, we have to use the important thing NavController.KEY_DEEP_LINK_INTENT. Hilt will do all of the magic for us.

The final step is to get the intent information. So let’s implement our Intent.parseSharedContent() operate.

As you may see on this code snippet, it’s worthwhile to use the next technique to entry the textual content information:

val textContent:String? = getStringExtra(Intent.EXTRA_TEXT)

And to entry the picture information, you must use:

val imageContent: Uri? = getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri

And that is it!

This function, together with many others, was carried out in my open supply undertaking. So you’ll want to try the repository and Thanks for studying.

I want the article practically Make your Android app a share goal. Obtain easy information from different purposes with Hilt and Compose | by Nikita Grishko | Jan, 2023 provides perspicacity to you and is beneficial for including collectively to your data

Make your Android app a share target. Receive simple data from other applications with Hilt and Compose | by Nikita Grishko | Jan, 2023

x