我使用zxing库来读取qr代码。它在MainActivity中运行良好。然后我想在片段中添加该代码。但意图集成商并没有为这个片段工作。
这是QrFragment中的代码;
package com.myapp.agpj.qr;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.google.zxing.integration.android.IntentIntegrator;
public class QrFragment extends Fragment {
public QrFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_qr, container, false);
Button scan = (Button) v.findViewById(R.id.bQr);
final Fragment activity = this;
scan.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan QR codes in the school premises");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
return v;
}
}
这会输出错误" IntentIntegator无法应用于android.support.v4.fragment"。