V
V
Vlad Ermolov2019-12-24 22:55:32
Java
Vlad Ermolov, 2019-12-24 22:55:32

How to get the value of a json file in a class in Android Studio that is on the network?

There is a class:

package com.example.app;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

class MyWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Uri uri = Uri.parse(url);
        if (uri.getHost() != null && uri.getHost().contains("example.com")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}

I want to add the value of the json file that is on the network instead of the value of example.com (domain address).
For example json:
[ {
        "id": 1569,
        "link": "https://site.com"
    } ]

and located at: example2.com/data.json
And one more thing: is it possible in JAVA to get the value after # in the link, for example, check if the link example.com/link#data contains the value "data" that comes after the # sign

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2019-12-25
@xez

Check out retrofit:
https://square.github.io/retrofit/
About data:

String s = "example.com/link#data";
String data = s.substring(s.indexOf("#")+1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question