为什么IF语句被跳过?

时间:2016-10-06 04:29:16

标签: android android-activity

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class ReaderActivity extends AppCompatActivity {
    private Button scan_btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reader);
        scan_btn = (Button) findViewById(R.id.scan_btn);
        final Activity activity = this;
        scan_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentIntegrator integrator = new IntentIntegrator(activity);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
                integrator.setPrompt("Scan");
                integrator.setCameraId(0);
                integrator.setBeepEnabled(false);
                integrator.setBarcodeImageEnabled(false);
                integrator.initiateScan();
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result.getContents() != null) {
            if(result.getContents().equals("Electronics A1")){
                Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
            }
            else {
                    Toast.makeText(this, result.getContents(),Toast.LENGTH_LONG).show();
            }
        }
        else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

大家好,目前正在为我的学校做一个项目。 现在我对程序有问题。

 if(result.getContents() != null) {
            if(result.getContents().equals("Electronics A1")){
                Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
如果应用程序忽略了这个问题,那么这是非常的。 声明的目的是当我扫描特定的qr代码时,它将转移到新的活动或做某事。

昨天该声明正在发挥作用,但今天突然间它无法正常工作......

你能帮助我吗? 目前刚刚进入android studio

0 个答案:

没有答案