Search code examples
androidjsondatabasesend

Send android string to JSON and display result in new window


I'm using the DVLA database and the JSON result is, eg:

{
"make": "VOLKSWAGEN",
"model": "Tiguan",
"sixMonthRate": "112.75",
"twelveMonthRate": "205.00",
"dateOfFirstRegistration": "23 July 2009",
"yearOfManufacture": "2009",
"cylinderCapacity": "1968cc",
"co2Emissions": "167 g/km",
"fuelType": "DIESEL",
"taxStatus": "Not taxed",
"colour": "SILVER",
"typeApproval": "M1",
"wheelPlan": "2 AXLE RIGID BODY",
"revenueWeight": "Not available",
"taxDetails": "Tax due: 06 February 2015",
"motDetails": "Expires: 23 July 2015",
"taxed": false,
"mot": true
}

My question is, by using android value from editText field

String str = results.getResults().get(0).getPlate();
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
editText.setText(str, TextView.BufferType.EDITABLE);

How do I send value "str" as: https://dvlasearch.appspot.com/DvlaSearch?licencePlate=**str**&apikey=DvlaSearchDemoAccount

And how do I display result in JSON or TEXT view in the new window/tab?

I try to use this bundle, BUT "putString" highlight as red and do not get how to send value to another activity. Intent intent = new Intent(MainActivity.this, DVLAresult.class); Bundle bundle = new Bundle(); intent.putString("PlateNumber", editText); intent.putExtras(bundle); startActivity(intent);

This is my second activity

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class DVLAresult extends AppCompatActivity {

        Bundle bundle = getIntent().getExtras();
        String finalPlateNumber = bundle.getString("PlateNumber");
}

Solution

  • The problem is that you are trying to put your string into the intent not the bundle.

    Try this:

    Intent intent = new Intent(MainActivity.this, DVLAresult.class);
    Bundle bundle = new Bundle();
    bundle.putString("PlateNumber", editText); //this line was the problem
    intent.putExtras(bundle);
    startActivity(intent);