I'm try to implement assigning cookies to android app without using WebView.
So I have /login
url and /api/*
urls which are protected by authorization.
I want send cookie after correct login and use this cookie to get protected urls from /api/*
How can I implement cookies in android application?
Asked
Active
Viewed 245 times
0

Nikolay Podolnyy
- 931
- 10
- 19
-
1`How can I implement cookies in android application?` depends on how you make network requests. Each approach has it's own way to handle cookies – Vladyslav Matviienko Sep 11 '19 at 07:03
-
I make network request with `AndroidNetworking`. But which approaches are exist? – Nikolay Podolnyy Sep 11 '19 at 07:11
-
`which approaches are exist` there are probably 100 of them. I won't list all of them, sorry. have you tried searching to find out how to work with cookies in AndroidNetworking? – Vladyslav Matviienko Sep 11 '19 at 07:14
-
Hah... I'm trying to understand the way of solution. But what I've heard from you @Vladislav is: 'There are many solutions,.. ' – Nikolay Podolnyy Sep 11 '19 at 07:18
-
actually no, I've said that there is a solution for every way of networking. The solution depends on the way you use. You are using `AndroidNetworking`, have you tried searching for how to use cookies in AndroidNetworking? – Vladyslav Matviienko Sep 11 '19 at 07:20
-
1Please check the Android Networking documentation: https://amitshekhar.me/Fast-Android-Networking/cookie.html – jordansilva Sep 11 '19 at 07:28
1 Answers
-1
As you are not using a WebView for calling your URLs and Cookies in general is just a way of storing small pieces of data I would use SharedPreferences instead.
https://developer.android.com/reference/android/content/SharedPreferences
Here you can store key pairs of strings, ints etc and reach from anywhere within your app.
Or for cookies you could use OKHttp like this answer suggests: How to implement cookie handling on Android using OkHttp?

just_user
- 11,769
- 19
- 90
- 135