J'ai une application et sur son activité principale il y a un bouton, en cliquant sur ce qui ouvre un fragment au centre de l'écran.
J'ai le code de travail qui ouvre la caméra au centre comme expliqué, mais je veux que cette simple vue de la caméra se transforme en scanner qr. J'ai maintenant ajouté la dépendance de la bibliothèque zxing. et comment le faire fonctionner lors de l'ouverture de la caméra? ne peut pas organiser le code. (dans la vue oncreate).
Toute aide serait grande s'il vous plaît.comment ouvrir une caméra avec un scanner de code qr?
//method in scan.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_scan, container, false);
if(checkCameraHardware(getActivity().getApplicationContext())){
zXingScannerView = new ZXingScannerView(getActivity().getApplicationContext());
//zXingScannerView.startCamera(); I tried something like this
mCamera = Camera.open();
mCamera.setDisplayOrientation(90);
Camera.Parameters params = mCamera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
mCamera.setParameters(params);
mPreview = new CameraPreview(this.getActivity(), mCamera);
//container.addView(mPreview);--->Remove this line
//Add this line
FrameLayout preview =(FrameLayout)view.findViewById(R.id.camera_preview);
preview.addView(mPreview);
}
// Inflate the layout for this fragment
return view;
}
//fragment_scan.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="layout.scan"
android:layout_centerInParent="true"
android:layout_marginTop="@dimen/nav_header_height"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginLeft="@dimen/fab_margin"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/camera_preview"
>
</FrameLayout>
</LinearLayout>
Vous pouvez trouver ce [link] (https://www.spaceotechnologies.com/qr-code-android-using-zxing-library/) utile. –
vous pouvez modifier le fichier CameraConfigurationUtils dans la bibliothèque zxing –