I have protected some hosted files with a password to avoid any unknow access but I don't know how to directly access these files from my application , I am using Volley library and I tried this :
private static final String URL = "http://user:password@mywebsite.com/file/json/";
public static void getData(final Context context) {
requestQueue = Volley.newRequestQueue(context.getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String somedata= response.getString("data");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Toast.makeText(context, "Error Loading Data\n Please Restart App", Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(jsonObjectRequest);
}
I realised that my app doesn't fetch data from my json file , but when I access the URL above from browser , it works perfectly