I'm trying to test volley request but keep getting null result. No response, no error detected. My minimum sdk is 23 and target sdk 31.
Here is my code On Main Activity
public class MainActivity extends AppCompatActivity {
Button btn;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=findViewById(R.id.button1);
tv=findViewById(R.id.tv1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String CT = Test_Koneksi();
tv.setText(CT);
}
});
}
private String Test_Koneksi() {
final String[] result = new String[1];
result[0]="Connection Failed";
String url = "http://192.168.81.68/query/connection_test.php";
StringRequest request = new StringRequest(Request.Method.GET,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
result[0] = response;
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
result[0]=error.getMessage();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(request);
return result[0];
}
}
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tbj_mobile" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true"
android:allowClearUserData="true"
android:fullBackupContent="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Tbj_Mobile" >
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have tried to call the connection via browser and its ok, I tried from the browser inside emulator so network connection is not the issue I guess.