0

I'm new to android development. I'm working on an application which calls the web services for registration, login, etc... Now I'm storing the url and other constants as a static final object in a class. Is this the best way of doing it or I should use preferences or string.xml for saving the url which assures secured when decompiling the apk?

Ram
  • 845
  • 1
  • 13
  • 26

2 Answers2

-1

Is this the best way of doing it or I should use preferences or string.xml for saving the url which assures secured when decompiling the apk?

Rooted phones can be modified to provide access to private preferences etc. Even if your code is obfuscated and the Strings encrypted, your URLs can still be exposed.

The answer is not to keep the URL a secret but rather to secure the web service calls in a reliable way. Your post does not have enough information to elaborate on what security would best suit your app / service. Take a look at OAuth ; how amazon AWS secures their web service calls. That is a good start.

Deepak Bala
  • 11,095
  • 2
  • 38
  • 49
-2

you should use preferences for your login credential as like the following, and hope u get him idear from it:

SharedPreferences sh_Pref;
Editor toEdit;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.yourlayout);

   sh_Pref = getSharedPreferences("Login Credentials", MODE_PRIVATE);
   EditText et_username=(EditText) findViewById(R.id.et_username);
   EditText et_password=(EditText)this.findViewById(R.id.et_password);
   Button btn_login=(Button)this.findViewById(R.id.btn_login);

btn_login.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

         username =     et_username.getText().toString();
         password =     et_password.getText().toString();
         sharedPrefernces();
         Toast.makeText(MyPoints.this, "Details are saved", 20).show();


        }
    });



    }

outside oncreate:

public void sharedPrefernces() {

  //  sh_Pref = getSharedPreferences("Login Credentials", MODE_PRIVATE);
    toEdit = sh_Pref.edit();
    toEdit.putString("Username", username);
    toEdit.putString("Password", password);
    toEdit.putBoolean("isLogedIn", true);
    Log.d("TripleVMusic", "username in pref= " + username);
     Log.d("TripleVMusic", "password in pref = " + password);
    toEdit.commit();

}
Farhan Shah
  • 2,344
  • 7
  • 28
  • 54