J'ai écrit un code pour accéder à l'API ci-dessous et obtenir les valeurs correspondantes des horaires de Namaz, mais la méthode OnResponse ne se fait pas être invoquée. J'ai donné des autorisations sur Internet dans le fichier manifeste Android. Je suis nouveau à Android, s'il vous plaît aider.
Pendant que l'installation de l'application ne demande pas aux autorisations Internet, même si je l'ai mentionnée dans le fichier manifeste. P>
import android.app.ProgressDialog; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.VolleyLog; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import org.json.JSONException; import org.json.JSONObject; public class NamazTiming extends AppCompatActivity { private TextView fazarId, zoharid, asarid, magribid, ishaid, location; private RequestQueue mQueue; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.namaz_timing); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle("Namaz Timings"); fazarId = findViewById(R.id.fazarid); zoharid = findViewById(R.id.zoharid); asarid = findViewById(R.id.asarid); magribid = findViewById(R.id.magribid); ishaid = findViewById(R.id.ishaid); location = findViewById(R.id.location); Button locationbutton = findViewById(R.id.locationbutton); mQueue = Volley.newRequestQueue(this); locationbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { jsonParse(); } }); } private void jsonParse() { //String loc = location.getText().toString().trim(); String url ="https://muslimsalat.com/uravakonda.json?key=ba8d0b5ba55c6db3cebbe3fefd6090f8"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(NamazTiming.this, "Entered onresponse", Toast.LENGTH_SHORT).show(); try { Toast.makeText(NamazTiming.this, "Entered into TRY", Toast.LENGTH_SHORT).show(); String Fazar = response.getJSONArray("items").getJSONObject(0).get("fajr").toString(); String Zohr = response.getJSONArray("items").getJSONObject(0).get("dhuhr").toString(); String Asar = response.getJSONArray("items").getJSONObject(0).get("asr").toString(); String Magrib = response.getJSONArray("items").getJSONObject(0).get("maghrib").toString(); String Isha = response.getJSONArray("items").getJSONObject(0).get("isha").toString(); fazarId.setText(Fazar); zoharid.setText(Zohr); asarid.setText(Asar); magribid.setText(Magrib); ishaid.setText(Isha); } catch (JSONException e) { e.printStackTrace(); Toast.makeText(NamazTiming.this, "Please enter the lccation name", Toast.LENGTH_SHORT).show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); Toast.makeText(NamazTiming.this, "Please enter the lccation name", Toast.LENGTH_SHORT).show(); } }); }
3 Réponses :
Vous devez ajouter votre code> objet code> à la file d'attente Volley (dans votre cas, exemple:
Muqueue code>) Pour que la demande soit exécutée. P>
mQueue.add (demande); code> p>
La permission d'Internet est une autorisation normale afin que le système Android ne posera pas la permission d'Internet. P>
Vous venez d'appeler cette ligne: p>
fin de la demande. P> mQueue.add (demande); code> p>
Ajouter ci-dessous Ligne après la méthode d'erreurListener à la fin de votre demande
mQueue.add("your request type");
Pouvez-vous s'il vous plaît partager le journal de Android Studio
Avez-vous essayé de déboguer votre code?