Giter Club home page Giter Club logo

simplescan's People

Contributors

cymplecy avatar

Watchers

 avatar

simplescan's Issues

App crashes if barcode scanner not present and a scan is attempted

What steps will reproduce the problem?
1. Run app without the barcode scanner installed
2. Attempt a scan
3.

What is the expected output? What do you see instead?
Expect a message saying scanner not installed. Usual practice is then to offer 
to install it.

What version of the product are you using? On what operating system?
V0.31
Target was Nexus One Android 2.2.2

Please provide any additional information below.

Here's a fix. In SimpleScanActivity.java change the OnClickListener method, 
then add the isIntentAvailable() method as follows:

/**
 * A call-back for when the user presses the back button.
 */
OnClickListener mScanListener = new OnClickListener() {
  public void onClick(View v) {

    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE","ONE_D_MODE");
    if (isIntentAvailable(SimpleScanActivity.this, "com.google.zxing.client.android.SCAN")) {            
      startActivityForResult(intent, 0);
    } else {
      Dialog confirmScannerInstall = new AlertDialog.Builder( SimpleScanActivity.this )
        .setIcon( R.drawable.icon )
        .setTitle( getString( R.string.app_name ) )
        .setMessage( "The Barcode reader is not present - install it now?")
        .setPositiveButton( "Yes", new DialogInterface.OnClickListener() {
          public void onClick( DialogInterface dialog, int whichButton ) {
            Uri uri = Uri.parse("market://search?q=pname:com.google.zxing.client.android");                        
            Intent installIntent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(installIntent);
          }
        })
        .setNeutralButton("No" , new DialogInterface.OnClickListener() {
          public void onClick( DialogInterface dialog, int whichButton ) {
            return;
          }
        })                
        .create();
      confirmScannerInstall.show();
    }
  }
};

public static boolean isIntentAvailable(Context context, String action) {
  final PackageManager packageManager = context.getPackageManager();
  final Intent intent = new Intent(action);
  List<ResolveInfo> list =
    packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);
  return list.size() > 0;
}



Original issue reported on code.google.com by [email protected] on 9 Feb 2011 at 2:50

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.