Produit des informations comme le nom, le prix, etc à l'aide de numéro de code à barres

Je développe une application qui utilise barcode pour obtenir de l'information sur le produit, après la numérisation de l' barcode.

Je ne veux pas l'utilisateur à installer ZXing barcode application séparément j'ai donc intégré la ZXing code dans mon projet. J'ai donc été en mesure d'obtenir les barcode ID number.

Je veux obtenir le informations sur le produit comme le nom du fabricant, le prix etc en utilisant le numéro de code à barres à l'aide de api de recherche google pour faire du shopping.

Voici le code que j'ai utilisé

public class JSONExampleActivity extends Activity {
TextView httpStuff; 
DefaultHttpClient client; 
JSONObject json;  
final static String URL = "https://www.googleapis.com/shopping/search"; 
String upc = "/v1/public/products?country=US&q=691464717759&restrictBy=gtin=691464717759";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);          
httpStuff = (TextView) findViewById(R.id.tvHttp); 
client = new DefaultHttpClient(); 
new Read().execute("items");                
}
public JSONObject products(String upc)  throws ClientProtocolException, IOException, JSONException {     
StringBuilder url = new StringBuilder(URL); 
url.append(upc);
HttpGet get = new HttpGet(url.toString());     
HttpResponse r = client.execute(get);   
int status = r.getStatusLine().getStatusCode(); 
if (status == 200) {
HttpEntity e = r.getEntity();         
String data = EntityUtils.toString(e);         
JSONObject timeline = new JSONObject(data); 
return timeline;    
} 
else {         
Toast.makeText(JSONExampleActivity.this, "error", Toast.LENGTH_SHORT);         
return null;  
} 
}  
public class Read extends AsyncTask<String, Integer, String> {      
@Override     
protected String doInBackground(String... params) {         
//TODO Auto-generated method stub         
try {                
json = products(upc);
return json.getString(params[0]);         
} catch (ClientProtocolException e) {             
//TODO Auto-generated catch block             
e.printStackTrace();        
} catch (IOException e) {             
//TODO Auto-generated catch block             
e.printStackTrace();         
} catch (JSONException e) {             
//TODO Auto-generated catch block            
e.printStackTrace();         
}         
return null;     
}  
@Override 
protected void onPostExecute(String result){     
httpStuff.setText(result);
} 
}

Mais je n'obtiens pas de texte dans httpStuff.

C'est le logcat:

D/SntpClient(61): request time failed: java.net.SocketException: Address family not    supported by protocol
W/System.err(793): org.apache.http.conn.ConnectTimeoutException: Connect to /209.85.175.95:443 timed out
W/System.err(793):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
W/System.err(793):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
W/System.err(793):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err(793):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err(793):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
W/System.err(793):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(793):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(793):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(793):  at com.android.example.jsonexample.JSONExampleActivity.products(JSONExampleActivity.java:53)
W/System.err(793):  at com.android.example.jsonexample.JSONExampleActivity$Read.doInBackground(JSONExampleActivity.java:77)
W/System.err(793):  at com.android.example.jsonexample.JSONExampleActivity$Read.doInBackground(JSONExampleActivity.java:1)
W/System.err(793):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
W/System.err(793):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
W/System.err(793):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
W/System.err(793):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
W/System.err(793):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
W/System.err(793):  at java.lang.Thread.run(Thread.java:1019)
D/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol

Merci de m'aider à trouver la raison pour laquelle je suis d'erreur.

avez-vous eu des solution pour cela? - Je mettre en place le même dans mon application pour l'un de nos client. Pouvez-vous svp me poster la solution?

OriginalL'auteur DSP | 2012-04-06