1. Download our Official Android App: Forums for Android!

Apps How to I implement a barcodscanner using the interfaces of Java in android

Discussion in 'Android Development' started by Okaid Oksa, Apr 8, 2016.

  1. Okaid Oksa

    Okaid Oksa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 8, 2016

    Apr 8, 2016
    1
    0
    5
    Male
    This is my MainActivity Class:
    package barscanner.sitf.barskender;

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.TextView;

    public class MainActivity extends AppCompatActivity{

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    @override
    public void onClick(View view) {
    // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
    // .setAction("Action", null).show();

    BarCodeReader reader = new BarCodeReader(MainActivity.this);
    //reader.setOnClickListener();
    reader.init();


    }
    });
    }

    @override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
    }

    @override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
    return true;
    }

    return super.onOptionsItemSelected(item);
    }



    }

    -------------------------------------------------------------------------

    This is my other class BarCodeScanner.java




    package barscanner.sitf.barskender;

    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.TextView;

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


    public class BarCodeReader implements BarCodeInterface {

    private Context mContext;
    private BarCodeReader result;

    public BarCodeReader(Context context) {
    this.mContext = context;
    }


    public void init()
    {
    new IntentIntegrator((Activity)mContext).initiateScan(IntentIntegrator.ALL_CODE_TYPES);
    }


    @override
    public BarCodeReader onResult() {
    return result;
    }
    }

    ------------------------------------------------------------------------
    And this is my interface class


    package barscanner.sitf.barskender;

    import android.content.Intent;
    import android.widget.TextView;

    /**
    * Created by Oket on 4/8/2016.
    */






    public interface BarCodeInterface {


    public BarCodeReader onResult();


    }

    ----------------------------------------------------------

    Im trying to call initiate a call using the interface class, and I tried several ways, but non of them functioned.

    Can someone some tips on this issue?


    Thnx a lot
     

    Advertisement

Share This Page

Loading...