简体   繁体   中英

What is the best way to store api-urls in android app?

I want to store the api urls somewhere , if I require I can change easily. If I keep in my server still I need url to access server which requires authentication. If I store in assets then there is a chance of stealing it by decompiling the apk. I don't want to hardcode urls in code or String.xml. Please suggest the best way where I can keep safe and change url easily. Thanks !!

The best way in your case is store api url's in server because you can change them later. You'd create one url to fetch your api urls. Build your app based on an architecture like this.

[
    {url: "/user/login", type:"login"},
    {url: "/user/register", type:"register"}
]

And don't forget anyone can see your server urls. It even doesn't have to decompiled because there are tools to watch device's network traffic:

make one Globalvariable.class in that you can add links.

String link="http:/---";

and access them any where in project like

String url=Globalvairable.link;

simple.

Use google tagmanager for saving url in json format and use that in your app. Its secure to save as it is encrypted and admin can change the url on the fly whenever needed.

use buildConfigField in build.gradle :)

More info in https://developer.android.com/studio/build/gradle-tips?hl=es-419

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM