如何在片段内调用核心zxing?

时间:2016-01-08 16:01:05

标签: android android-fragments zxing

疯狂得到结果。 基本上点击我需要启动相机的按钮,扫描条形码,并收到结果(如果有的话)。

这是片段:

package itxxxxviews;

import android.app.ProgressDialog;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import it.xxx.R;
import it.xxx.mappers.ApiMapper;
import it.xxx.models.ModelCampaign;
import it.xxx.models.ModelMemberCard;
import it.xxx.models.SupportDialog;

public class DashboardFragment extends Fragment {

    private TextView please_scan_card, name_campaign, debug;
    private EditText card_number;
    private BaseApp app;
    private View v;
    private NfcAdapter mNfcAdapter;
    private Button mButtonSearch, mButtonScan;
    private List<ModelMemberCard> memberCardList = new ArrayList<ModelMemberCard>();
    private CustomListMemberCardAdapter adapter;
    private Fragment fragment;

    @Override
    public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        fragment = this;

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        v = inflater.inflate(R.layout.dashboard_fragment,container,false);

        app = (BaseApp) getActivity();
        name_campaign = (TextView) v.findViewById(R.id.name_campaign);
        card_number = (EditText) v.findViewById(R.id.card_number);
        mButtonSearch = (Button) v.findViewById(R.id.button_search);
        mButtonScan = (Button) v.findViewById(R.id.button_start_scan);

        debug = (TextView) v.findViewById(R.id.debug);





        mButtonSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                adapter = new CustomListMemberCardAdapter(app, memberCardList);
                String card = card_number.getText().toString();
                getMemberCard(token, card);

            }
        });

        mButtonScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                 // here I need to start the scan...
                  IntentIntegrator.forSupportFragment(fragment).initiateScan();


            }
        });


        setDashboard();

        return v;
    }

    private void setDashboard() {

    }



}

基本上,在APP崩溃并进入日志后,它(尝试)启动相机:

       01-08 16:46:27.975  12409-12409/it.xxx E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.checkSelfPermission
        at com.journeyapps.barcodescanner.CaptureManager.openCameraWithPermission(CaptureManager.java:234)
        at com.journeyapps.barcodescanner.CaptureManager.onResume(CaptureManager.java:225)
        at com.journeyapps.barcodescanner.CaptureActivity.onResume(CaptureActivity.java:42)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1209)
        at android.app.Activity.performResume(Activity.java:5450)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2909)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2948)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2354)
        at android.app.ActivityThread.access$700(ActivityThread.java:159)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5419)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
        at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案