Hirdetés
Új hozzászólás Aktív témák
-
[KgP].Robot
aktív tag
Sziasztok!
Egy AsyncDownloader osztallyal lenne gondom. Ketto is.
1: onPreExecute metodusban elinditok egy ProgressDialogot, hogy az API-val torteno kommunikacio alatt tudja a user, hogy dolgozunk... Sajnos nem jelenik meg es nem tudom, hogy miert.2: OKHTTP respons-nal ha pl 500-as hibakodot kapok vissza, akkor a message-ben "Internal server error" uzenet kerul. Ez azert baj, mert ott egy custom uzenetnek kene lennie, amit visszakuld a szerver. Erre azert lenne szuksegem, mert ez alapjan tudnam kezelni a kiveteleket. De igy, hogy az OKHTTP kicsereli a gyeri uzenetre, sajnos nincs lehetosegem.
Ezekre szeretnek megoldast talalni.Async class:
public class AsyncDownloader extends AsyncTask<String, Void, String> {
public static final String TAG = AsyncDownloader.class.getSimpleName();
private Context context;
private ProgressDialog dialog;
public AsyncDownloader(Context ctx) {
context = ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(context);
dialog.setMessage("Loading...");
dialog.setProgressStyle(dialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.show();
}
@Override
protected String doInBackground(String... params)
{
String url = params[0];
String bodyparam = params[1];
String user_agent = params[2];
String content_type = params[3];
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse(content_type);
RequestBody body = RequestBody.create(mediaType, bodyparam);
Request request = new Request.Builder()
.url(url)
.post(body)
.addHeader("user-agent", user_agent)
.addHeader("content-type", content_type)
.build();
Call call = client.newCall(request);
Response response = null;
String jsonData = null;
try {
response = call.execute();
if (response.isSuccessful()) {
jsonData = response.body().string();
} else {
jsonData = null;
}
} catch (IOException e) {
e.printStackTrace();
}
return jsonData; //This is returned to onPostExecute()
}
@TargetApi(Build.VERSION_CODES.CUPCAKE)
@Override
protected void onPostExecute(String jsonData)
{
super.onPostExecute(jsonData);
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}es igy hivom meg:
response = downloader.execute(list.get(0), list.get(1), list.get(2), list.get(3)).get();
Új hozzászólás Aktív témák
- -40%! Legújabb innovációk! ÚJ!! HP EliteBook 640 G10 - i7-1365U 16GB 512GB iris Xe, Gar: 2024.11.06.
- XPS 9320 27% 13.4" 3.5K OLED érintő i7-1260P 16GB 512GB NVMe ujjlolv IR kam gar
- Macbook Pro 16" M1 Pro 2021 - 10 GPU, 16 CPU, 16GB RAM, 1 TERA SSD - garancia (12)
- BESZÁMÍTÁS! Asrock B450M R5 4500 16GB DDR4 512GB SSD GTX 1660 Super 6GB Zalman T3 Plus DeepCool 400W
- Precision 7760 27% 17.3" FHD IPS i7-11850H RTX A3000 32GB 512GB NVMe magyar vbill gar
- AKCIÓ!!! Sosemhasznált! HP OmniBook 5 i7-1355U 16GB 1TB 16" FHD+ Gar.: 1 év
- iPhone 12 Pro 128GB 100% (3hónap garancia)- ÚJ EREDETI AKKUMULÁTOR - AKCIÓ
- Telefon felvásárlás!! Samsung Galaxy S21/Samsung Galaxy S21+/Samsung Galaxy S21 Ultra
- ÁRGARANCIA!Épített KomPhone i5 12400F 16/32/64GB RAM RTX 3060 12GB GAMER PC termékbeszámítással
- szinteÚJ 2030 Gar! Dell Pro Max 14 Ryzen AI 9 HX PRO 370 32GB LPDDR5X 1TB NVMe SSD
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest

