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 !!
            Asked
            
        
        
            Active
            
        
            Viewed 1.2k times
        
    4 Answers
7
            
            
        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:
- Wireshark
- Packet Capture
 
    
    
        Ozgur
        
- 3,738
- 17
- 34
- 
                    is there any other option a part from this? – Arbaz.in Mar 25 '19 at 10:38
- 
                    I do not know, this solution easy. – Ozgur Mar 25 '19 at 11:22
1
            
            
        use buildConfigField in build.gradle :)
More info in https://developer.android.com/studio/build/gradle-tips?hl=es-419
 
    
    
        Diego Restrepo
        
- 81
- 8
 
    
    
        ariel
        
- 253
- 5
- 9
- 
                    do you know any advantage of using `buildConfigField` for URL? Is there any security benefit? – AADProgramming Nov 18 '18 at 15:09
- 
                    well..is more secure than other proposals like constants, resources, but the main benefit is the versatility of handle different configs for different environments. – ariel Nov 21 '18 at 13:49
0
            
            
        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.
 
    
    
        AskNilesh
        
- 67,701
- 16
- 123
- 163
 
    
    
        Ravina Bhavsar
        
- 67
- 7
0
            
            
        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.
 
    
    
        himb2001
        
- 1,371
- 1
- 10
- 7
