TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mohsin Arif
294
6k
138.7k
how can i call api without key in Volley ?
Mar 10 2020 11:59 AM
hellow guys below is my code, i want to get data from api and populate in graph in android but when i call api its shows error please help me, how can i call , api which have no any key
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public
class
MainActivity extends AppCompatActivity {
private
TextView mTextViewResult;
private
RequestQueue mQueue;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextViewResult = findViewById(R.id.text_view_result);
Button buttonParse = findViewById(R.id.button_parse);
mQueue = Volley.newRequestQueue(
this
);
buttonParse.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View v) {
jsonParse();
}
});
}
private
void
jsonParse() {
String url =
"http://marjanjewellers.co/bilal/api.php"
;
JsonObjectRequest request =
new
JsonObjectRequest(Request.Method.GET, url, null,
new
Response.Listener<JSONObject>() {
@Override
public
void
onResponse(JSONObject response) {
try
{
JSONArray jsonArray = response.getJSONArray(
"0"
);
//here what i do
for
(
int
i = 0; i < jsonArray.length(); i++) {
JSONObject employee = jsonArray.getJSONObject(i);
//String firstName = employee.getString("firstname");
//int age = employee.getInt("age");
// String mail = employee.getString("mail");
// mTextViewResult.append(firstName + ", " + String.valueOf(age) + ", " + mail + "\n\n");
}
}
catch
(JSONException e) {
e.printStackTrace();
}
}
},
new
Response.ErrorListener() {
@Override
public
void
onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
}
and api response is like this
[{
"id"
:
"1"
,
"altitude"
:
"95.5"
,
"airpressure"
:
"98.45"
,
"temperature"
:
"45.89"
,
"pulserate"
:
"85"
}]
Reply
Answers (
1
)
Obfuscation/Hiding C# dll code
C# code -Compare 2 pdf and give output as 2 pdfs with color