Дизайн приложения
Я хочу, чтобы приложение динамически получало чат [идентификатор группы и заголовок] по API-ссылке
Код: Выделить всё
https://api.telegram.org/bot/getUpdates
Код: Выделить всё
{
"update_id": 8393,
"message": {
"message_id": 3,
"from": {
"id": 7474,
"first_name": "AAA"
},
"chat": {
"id": ,
"title": ""
},
"date": 25497,
"new_chat_participant": {
"id": 71,
"first_name": "NAME",
"username": "YOUR_BOT_NAME"
}
}
}
Код: Выделить всё
private void getChatId() {
botToken = (EditText) findViewById(R.id.botToken);
telegramApiUrl = "https://api.telegram.org/bot"+botToken.getText().toString()+"/getUpdates";
JsonArrayRequest request = new JsonArrayRequest(com.android.volley.Request.Method.GET, telegramApiUrl, null, new Response.Listener() {
@Override
public void onResponse(JSONArray response) {
try {
for(int i=0; i < response.length(); i++){
JSONObject jsonObject = response.getJSONObject(i);
String id = jsonObject.getString("chat").toString();
String idUser = jsonObject.getString("id").toString();
resultToken.setText(id);
}
}catch (Exception e){
resultV.setText(e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
Volley.newRequestQueue(this).add(request);
}
решено с использованием gson lib, ты.
Подробнее здесь: https://stackoverflow.com/questions/783 ... m-api-link
Мобильная версия