android什么叫服务器,android - 我的Android Apk的服务器URL是什么? - SO中文参考 - www.soinside.com...

汪德明
2023-12-01

[我正在使用PHP JSON Volley来验证我的登录活动。目前,我正在提供localhost和IP地址来测试我的应用程序(请在下面找到我的代码)。但是,当生成APK时,应提供什么URL?请指导。public class LoginActivitywithConnection extends Activity {

private static final String TAG = "LoginActivitywithConnection";

private Button btnLogin;

private Button btnLinkToRegister;

private EditText usernameEditText;

private EditText inputPassword;

private ProgressDialog pDialog;

private SessionManager session;

private DbHandler db;

String userType;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login);

Log.i(TAG, "entered");

Intent i = this.getIntent();

Bundle data = i.getExtras();

if (data != null) {

String buttonClicked = data.getString("ButtonClicked");

if (buttonClicked.equals("asha")) {

userType = "asha";

} else if (buttonClicked.equals("anm")) {

userType = "anm";

} else if (buttonClicked.equals("doc")) {

userType = "doc";

} else if (buttonClicked.equals("sdm")) {

userType = "sdm";

}

}

usernameEditText = (EditText) findViewById(R.id.username);

inputPassword = (EditText) findViewById(R.id.password);

btnLogin = (Button) findViewById(R.id.login);

btnLinkToRegister = (Button) findViewById(R.id.register);

// Progress dialog

pDialog = new ProgressDialog(this);

pDialog.setCancelable(false);

}

public void loginCLick(View view) throws SocketException {

Log.i(TAG, "entered login");

String username = usernameEditText.getText().toString().trim();

String ashaphno = username;

String password = inputPassword.getText().toString().trim();

// Check for empty data in the form

if (!ashaphno.isEmpty() && !password.isEmpty()) {

chkStatus();

// login user

checkLogin(ashaphno, password);

Log.i(TAG, "username(ashaphone)" + username);

Intent i;

}

}

// Link to Register Screen

public void clickregister(View view) {

Intent i = new Intent(getApplicationContext(),

AshaRegisterActivity.class);

startActivity(i);

finish();

}

/**

* function to verify login details in mysql db

*/

public void checkLogin(final String ashaphno, final String password) {

// Tag used to cancel the request

String tag_string_req = "req_login";

pDialog.setMessage("Logging in ...");

pDialog.show();

StringRequest strReq = new StringRequest(Request.Method.POST,

Constants.URL_LOGIN, new Response.Listener() {

@Override

public void onResponse(String response) {

Log.d(TAG, "Login Response: " + response.toString());

pDialog.dismiss();

try {

JSONObject jsonObject = new JSONObject(response.substring(response.indexOf("{"), response.lastIndexOf("}") + 1));

boolean error = jsonObject.getBoolean("error");

// Check for error node in json

if (!error) {

// user successfully logged in

// Create login session

Log.i(TAG, "loginactivity" + userType);

if (userType.equals("asha")) {

JSONObject asha = jsonObject.getJSONObject("asha");

String username = asha.getString("AshaUsername");

String phone = asha.getString("Ashaphno");

if (username.equals(phone)) {

// Launch main activity

Intent intent = new Intent(LoginActivitywithConnection.this,

LoginOpeningPageAsha.class);

Bundle b = new Bundle();

b.putString("username", ashaphno);

intent.putExtras(b);

startActivity(intent);

finish();

}

} else if

(userType.equals("anm")) {

Intent i;

i = new Intent(LoginActivitywithConnection.this, LoginOpeningPageANM.class);

Bundle b = new Bundle();

b.putString("username", ashaphno);

i.putExtras(b);

startActivity(i);

}

} else {

// Error in login. Get the error message

String errorMsg = jsonObject.getString("message");

Toast.makeText(getApplicationContext(),

errorMsg, Toast.LENGTH_LONG).show();

Log.i(TAG, "error" +

errorMsg);

}

} catch (JSONException e) {

// JSON error

e.printStackTrace();

Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();

}

}

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError volleyError) {

Log.e(TAG, "Login Error: " + volleyError.getMessage());

String message = null;

if (volleyError instanceof NetworkError) {

message = "Cannot connect to Internet...Please check your connection!";

} else if (volleyError instanceof ServerError) {

message = "The server could not be found. Please try again after some time!!";

} else if (volleyError instanceof AuthFailureError) {

message = "Cannot connect to Internet...Please check your connection!";

} else if (volleyError instanceof ParseError) {

message = "Parsing error! Please try again after some time!!";

} else if (volleyError instanceof NoConnectionError) {

message = "Cannot connect to Internet...Please check your connection!";

} else if (volleyError instanceof TimeoutError) {

message = "Connection TimeOut! Please check your internet connection.";

}

Toast.makeText(getApplicationContext(),

message, Toast.LENGTH_LONG).show();

String erroridentifier = handleServerError(volleyError, getApplicationContext());

Log.e(TAG, "Login Erroridentifier: " + erroridentifier);

hideDialog();

}

}) {

@Override

protected Map getParams() {

// Posting parameters to login url

Map params = new HashMap();

params.put("AshaUsername", ashaphno);

params.put("ASHApwd", password);

return params;

}

};

DefaultRetryPolicy retryPolicy = new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

strReq.setRetryPolicy(retryPolicy);

// Adding request to request queue

AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

}

常量类:public class Constants {

private static final String ROOT_URL ="http://192.168.43.6/Android/v1/";

// Server user login url

public static String URL_LOGIN = ROOT_URL+"ashaLogin.php";

}

当用户下载此apk时,服务器URL(非本地)将是什么?

 类似资料: