long story quick , im IT guy , i have learned basic of Python and now i want to learn java but currently im doing a project in android studio without much knowledge so i dont have time to learn java for the moment , well im in a situation that is making me crazy.Project is IPTV player, im trying to get string with OkHttp3 and attach it to end of IPTV link to make it playable , i try GET with Postman and i get the result , i create new project in android studio and try OkHttp3 for first time (i saw youtube video), and i can succesfuly get the respond i want from OkHttp3 but the respond i get into textview, now in my main project for iptv i want to store the response into String i think and attach to the end of the IPTV link , i try to store response into textview but app crashes, i belive the good way is to store into String , so far down public class i done : TextView mCodeFromUrl;
my OkHttp3 code below onCreate is :
mCodeFromUrl = findViewById(R.id.test1);
OkHttpClient client = new OkHttpClient();
String url = "http://192.168.100.6/1.php";
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NonNull Call call, @NonNull IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
if (response.isSuccessful()){
assert response.body() != null;
String myResponse = response.body().string();
TVDetailsActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mCodeFromUrl.setText(myResponse);
}
});
}
}
});
this works for new project with textview , but in main project i get crash , is there any possibility to get string and store into another class or i dont know , im so out of ideas , i also tried to create string below public class : String Test1 = "testurl";
then into OkHttp3 code it try to give my string Test1 the response like this : Test1 = Test1 + myResponse;
Down below into the code i try to add : + Test1
code: ExoPlayerFragment exoPlayerFragment = ExoPlayerFragment.newInstance(itemChannel.getChannelUrl() + Test1);
fragmentManager.beginTransaction().replace(R.id.playerSection, exoPlayerFragment).commitAllowingStateLoss();
then the app load perfect but when im about to get the response and place it behind the IPTV link i get the string and not the response like this ...lista.m3u8testurl
Help me please and if possibility any recommended youtube channel to learn java, Thanks a lot
更新:是否可以创建新类并将所有OkHttp3代码放入其中,然后在需要的地方使用代码执行?因为当客户端单击频道以观看电视时,并且在后台执行OkHttp3,并且响应在IPTV链接后面,然后客户端可以播放IPTV时,我想获得响应。