Back

how can i get only email value in a string (Android)

  • 0
  • Databases
Drake
2 May, 2023, 04:19

Could you have done result.toMap() instead?

TL;DR
The user wants to extract only the email value from a string in Android. They have provided a code snippet but are struggling to retrieve the email value from a map. Another user suggests type checking and casting the values, and provides an example of how to do it. The original user confirms that this solution works for them.
Akshaydeep
2 May, 2023, 04:20

not working i tried

Drake
2 May, 2023, 04:21

What happened?

Akshaydeep
2 May, 2023, 04:22

i dont know it was not working

Akshaydeep
2 May, 2023, 04:22

maybe you guys can provide proper tutorials on java for android

Akshaydeep
2 May, 2023, 04:27

it says it cannot be cast to model class

Drake
2 May, 2023, 04:28

What exactly is your code and full error?

Akshaydeep
2 May, 2023, 04:31

i dont have the old code now

Akshaydeep
2 May, 2023, 04:31

above code is working for me

Akshaydeep
2 May, 2023, 04:32

result.toMap() is there but we dont know how can we get each value as string

Akshaydeep
2 May, 2023, 04:33

can you share how to do this result.toMap() method & then get a email value as string

Drake
2 May, 2023, 04:43

The map is a Map<String, Any> map. You'd have to type check/cast the values like (String) (result.toMap().get("user_email"))

Akshaydeep
2 May, 2023, 05:07

what is any?

Akshaydeep
2 May, 2023, 05:08

<String,String> or <String,Object>

Akshaydeep
2 May, 2023, 05:08

i have known

Akshaydeep
2 May, 2023, 05:08

what is Any ?

Akshaydeep
2 May, 2023, 05:10

told u your methods are complicated

Drake
2 May, 2023, 05:27

I think Any in kotlin is ? In java. Not sure though. I don't know much about kotlin or java

Drake
2 May, 2023, 05:28

I blame kotlin and java 😜

Akshaydeep
2 May, 2023, 05:46

yes exactly you also dont know the solution

Akshaydeep
2 May, 2023, 05:46

thats why i have solved my self above

Akshaydeep
2 May, 2023, 05:46

and this is working

Drake
2 May, 2023, 15:08

Android/Java/Kotlin is just a pain, but here you go:

Drake
2 May, 2023, 15:09
TypeScript
        Client client = new Client(getApplicationContext())
                .setEndpoint("http://10.0.2.2/v1") // Your API Endpoint
                .setProject("test"); // Your project ID

        Databases databases = new Databases(client);

        try {
            databases.getDocument(
                    "default",
                    "test",
                    "parent",
                    new CoroutineCallback<>((result, error) -> {
                        if (error != null) {
                            error.printStackTrace();
                            return;
                        }

                        Map map = result.getData();
                        String name = (String) map.get("name");
                        System.out.println(name);
                    })
            );
        } catch (AppwriteException e) {
            throw new RuntimeException(e);
        }
Akshaydeep
3 May, 2023, 04:34

@Steven thanks

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more