I've been trying to create a json format to display it on the android app so I can use it on my ewallet project but I've been getting error Access denied finding property "ro.serialno" or " org.json.JSONException: End of input at character "
I think the main reason of the connection is the error of Access denied, also before the Run debugging I've been seein a lots of denied permissions.
This is my code on the login for the e-wallet:
package RAMS.e_wallet;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
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.StringRequest;
import com.android.volley.toolbox.Volley;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class Login extends AppCompatActivity {
private static EditText etNumber, etPassword;
private static String phone = null;
private static final String password = null;
private static final String URL = "http://192.168.1.218/login1/login/login.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etNumber = findViewById(R.id.username);
etPassword = findViewById(R.id.password);
}
public void backToMenu (View v){
phone = etNumber.getText().toString().trim();
if(!phone.equals("")){
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(Login.this, jsonObject.getString("success"),Toast.LENGTH_LONG).show();
}
catch (JSONException e){
e.printStackTrace();
Toast.makeText(Login.this, "e"+e.toString(), Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Login.this, "err"+error.toString(),Toast.LENGTH_LONG).show();
}
}){
@NotNull
@Override
public Map<String, String> getParams() throws AuthFailureError {
Map<String, String> data = new HashMap<>();
data.put("phone_number", phone);
return data;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
}
else {
Toast.makeText(this, "Fields cannot be empty!", Toast.LENGTH_SHORT).show();
}
}
public void switchRegister (View view){
Intent intent = new Intent(this, Register.class);
startActivity(intent);
finish();
}
}
here's my dependencies on the gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
}
my PHP code for the login
<?php
class Reply{
function procced(){
if(isset($_POST['phone']))
{
require_once "conn.php";
require_once "validate.php";
$phone = var_dump($_POST['phone']);
$sql = "select * from users where phone_number= '$phone'";
$result = $conn->query($sql);
if($result->num_rows > 0)
{
session_start();
$data=["response"=>"success"];
return json_encode($data);
}
else{
$data=["response"=>"error"];
return json_encode($data);
}
}
$data=["response"=>"error"];
return json_encode($data);
}
}
?>
and the Json format that i've been trying :
package com.example.json;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DownloadManager;
import android.os.Bundle;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainActivity extends AppCompatActivity {
private TextView mTextview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextview = findViewById(R.id.textviewresult);
OkHttpClient client = new OkHttpClient();
String url = "http://192.168.1.218/jsonlogin/json.php";
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
if(response.isSuccessful()){
String myResponse = response.body().toString();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mTextview.setText(myResponse);
}
});
}
}
});
}
}
the json code is in a different activity because i'm trying to display numerous data for a textview
also, all of the codes have the internet permission on their manifests