Reputation: 77
I have followed a tutorial to integrate zxing into my application and that has worked great, the only problem now is that when I scan the qr code nothing launches, I am a complete newb and some input would be a great help. My java is:
public class MainActivity extends Activity implements OnClickListener {
private Button scanBtn;
private TextView formatTxt, contentTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBtn = (Button)findViewById(R.id.scan_button);
formatTxt = (TextView)findViewById(R.id.scan_format);
contentTxt = (TextView)findViewById(R.id.scan_content);
scanBtn.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
//respond to clicks
if(v.getId()==R.id.scan_button){
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
I would like to launch into the browser but I'm sure I'm missing something
Upvotes: 0
Views: 150
Reputation: 8488
Once you have the string from the QR Code, you need to launch browser in following way:
String url = "Url String";
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
try {
// Start the activity
startActivity(myIntent);
this.finish();
} catch (ActivityNotFoundException e) {
// Raise on activity not found
Toast toast = Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT);
}
Hope this helps
Upvotes: 0
Reputation:
You never actually launch any of your results. If you scanned text that turned out to be a website link you would need to launch an intent for the web browser to open.
In activity result after you read the results in you would do something like this:
Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse(<INSERT URL>));
startActivity(i);
Upvotes: 1