When I scan QR code it's getting a data on result.getContents
but didn't pass the data on JSONObject obj
just directing go on Catch
block
data get pass to this line JSONObject obj = new JSONObject(result.getContents());
but when start to Debug
then its not pass the data on 'obj' in above line.
here is my code :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
//if qrcode has nothing in it
if (result.getContents() == null) {
Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
} else {
//if qr contains data
try {
//converting the data to json
JSONObject obj = new JSONObject(result.getContents());
//setting values to textviews
if(obj.has("FN")) {
etFirstName.setText(obj.getString("FN"));
}
if(obj.has("N")) {
etLastName.setText(obj.getString("LN"));
}
if(obj.has("TITLE")) {
etTitle.setText(obj.getString("TITLE"));
}
if(obj.has("STATUS")) {
etStatus.setText(obj.getString("STATUS"));
}
if(obj.has("EMAIL")) {
etEmail.setText(obj.getString("EMAIL"));
}
if(obj.has("TEL;TYPE=work")) {
etPhoneHome.setText(obj.getString("TEL;TYPE=work"));
}
if(obj.has("TEL;TYPE=cell")) {
etPhonePrimary.setText(obj.getString("TEL;TYPE=cell"));
}
if(obj.has("ADR;TYPE=work")) {
etAddressLine1.setText(obj.getString("ADR;TYPE=work"));
}
if(obj.has("Street")) {
etAddressLine2.setText(obj.getString("Street"));
}
if(obj.has("Street")) {
etCity.setText(obj.getString("Street"));
}
if(obj.has("zip")) {
etZip.setText(obj.getString("zip"));
}
} catch (JSONException e) {
Log.e(TAG, "notification= error" + e.toString());
e.printStackTrace();
/*etFirstName.setText(result.getContents());
etLastName.setText(result.getContents());
etTitle.setText(result.getContents());
etEmail.setText(result.getContents());*/
//if control comes here
//that means the encoded format not matches
//in this case you can display whatever data is available on the qrcode
//to a toast
Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
Logcat see below :
03-09 11:23:06.909 297-678/? E/SimpleSoftOMXComponent: 3
03-09 11:23:07.127 297-665/? E/audio_a2dp_hw: adev_set_parameters: ERROR: set param called even when stream out is null
03-09 11:23:12.899 26980-26980/com.example.crm E/AddContactActivity: notification= errororg.json.JSONException: Value BEGIN of type java.lang.String cannot be converted to JSONObject
03-09 11:23:13.040 297-8371/? E/SimpleSoftOMXComponent: 1
03-09 11:23:13.040 297-8371/? E/SimpleSoftOMXComponent: 2
03-09 11:23:13.041 297-8371/? E/SimpleSoftOMXComponent: 3
JSON Response Data like below code:
BEGIN:VCARD,
VERSION:2.1
FN:sss sss
N:sss;sss
TITLE:PHD
TEL;CELL:1111111111
TEL;WORK;VOICE:2222222222
TEL;HOME;VOICE:8888888888
EMAIL;HOME;INTERNET:abc@example.com
EMAIL;WORK;INTERNET:abc@example.com
URL:http://ABC@ABC.COM
ADR:;;sample address;ss;;102103;US
ORG:ss
END:VCARD
Search everywhere but I don't get any result for this problem so plzzz help me:)
Thanks&Regards Sandeep Patel