Androidã¢ããªã§ãã¼ã³ã¼ããèªã¿ãããã ãã©
ãããã°ãzxing ã使ãã°ããã£ã¦ãã¨ã¯ããã«åããã
ãã¦ãã©ãããã³ã¼ããæ¸ãã°ããã®ãã調ã¹ã¦ã¿ãããããããã¨ããã©ããããã¨ãæ¸ãã¦ããããã°ãªã©ãçºè¦ã
zxing ããã¦ã³ãã¼ããã¦ãandroid ã¢ããªã®ãµã³ãã«ãå«ã¾ãã¦ããã®ã§ããã®ã³ã¼ããèªãã§ã¿ãããã¨æã£ããã©ãæå¤ã¨ããªã¥ã¼ã ãããã
zxing ã®ãµã¤ãã§ãWikiããã§ãã¯ãã¦ããããããããã¼ã¸ãçºè¦ã
â«ScanningViaIntent - zxing
æ¢ã«QRã³ã¼ãã¹ãã£ãã¼ãã¤ã³ã¹ãã¼ã«æ¸ã¿ãªããããã ãã®ã³ã¼ãã§èªã¿åãããããã
public Button.OnClickListener mScan = new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.setPackage("com.google.zxing.client.android"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } }; public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); // Handle successful scan } else if (resultCode == RESULT_CANCELED) { // Handle cancel } } }
ã»ã»ã¼ã
ããããActivityãå¼ã³åºãã¨ããã§ä¾å¤å¦çã追å ãã¦ãzxingã®Activityãç¡ãã£ããããã¤ã¢ãã°ã表示ããã³ã¼ãã追å ãã¦ãzxingã®QRã³ã¼ãã¹ãã£ãã¼ã®ã¤ã³ã¹ãã¼ã«ãä¿ãã
Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.setPackage("com.google.zxing.client.android"); try { startActivityForResult(intent, REQUEST_CODE); } catch (ActivityNotFoundException e) { showDialog(R.id.download_barcode_scanner); }
ã§ãonCreateDialog() ãã¤ã¢ãã°ã表示ãã¦ãã¦ã³ãã¼ããããã©ãããã¦ã¼ã¶ã¼ã«ç¢ºèªãã¦ããã£ã¦ãAndroidãã¼ã±ããã®QRã³ã¼ãã¹ãã£ãã¼ã®ãã¼ã¸ã«é·ç§»ã
@Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) return; switch (dialogId) { case R.id.download_barcode_scanner: Uri uri = Uri.parse("market://details?id=com.google.zxing.client.android"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); break; default: // hogehoge break; } }
ããã§ã¦ã¼ã¶ã¼ãã¤ã³ã¹ãã¼ã«ãã¦ãããã°OKï¼
IS01ã¨ãIS03ã«æåããå
¥ã£ã¦ããã¼ã³ã¼ããªã¼ãã¼ãIntentçµç±ã§ä½¿ãæ¹æ³ã£ã¦ã©ããã«è½ã¡ã¦ãªãããªã¼ã