user1224508
user1224508

Reputation: 57

Zxing when qr code is scanned it reverts to menu

I have the zxing library imported into my project and the scanner works like a charm but when i scan a qr code it says Qr code found and goes back to the menu i had set up is there any way to show the result and set it to open the url

package com.Qrgolf.App;

import java.util.regex.Pattern;

import com.google.zxing.Result;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    Button scan = (Button) findViewById(R.id.SCANBUTTON);

    scan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
        }
    });
    };

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                // Handle successful scan
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }
}

Upvotes: 0

Views: 449

Answers (1)

FoamyGuy
FoamyGuy

Reputation: 46856

You should consider going back to your old questions and accepting answers if they were correct.

Also you need to change the onActivityResult() method to do whatever it is that you want to do with the resulting String from the QR.

here is an example:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(android.net.Uri.parse(contents));
            startActivity(intent);
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

Upvotes: 1

Related Questions