使用Android Studio

一、在build.gradle(Module:app)添加代码  下载,调用插件

 1 apply plugin: 'com.android.application'
2
3 android {
4 compileSdkVersion 24
5 buildToolsVersion "24.0.1"
6
7 defaultConfig {
8 applicationId "com.example.ly.scanrfid"
9 minSdkVersion 19
10 targetSdkVersion 24
11 versionCode 1
12 versionName "1.0"
13 }
14 buildTypes {
15 release {
16 minifyEnabled false
17 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 }
19 }
20 repositories {
21 mavenCentral()
22 maven {
23 url "http://dl.bintray.com/journeyapps/maven"
24 }
25 }
26 }
27
28 dependencies {
29 compile fileTree(dir: 'libs', include: ['*.jar'])
30 testCompile 'junit:junit:4.12'
31 compile 'com.android.support:appcompat-v7:24.2.1'
32 // Supports Android 4.0.3 and later (API level 15)
33 compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
34
35 // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
36 // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
37 compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'
38
39 // Convenience library to launch the scanning and encoding Activities.
40 // It automatically picks the best scanning library from the above two, depending on the
41 // Android version and what is available.
42 compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
43
44 // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
45 // This mostly affects encoding, but you should test if you plan to support these versions.
46 // Older versions e.g. 2.2 may also work if you need support for older Android versions.
47 compile 'com.google.zxing:core:3.0.1'
48 }

二、添加权限

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ly.scanrfid">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application> </manifest>

三、Activity代码

package com.example.ly.scanrfid;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast; import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} // 扫描按钮点击监听事件
public void clickScan(View view) {
//扫描操作
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.initiateScan();
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 跳转扫描页面返回扫描数据
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
// 判断返回值是否为空
if (scanResult != null) {
//返回条形码数据
String result = scanResult.getContents();
Log.d("code", result);
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}
}
}

Android 扫描条形码(Zxing插件)的更多相关文章

  1. Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果

      Android 高手进阶(21)  版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...

  2. 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错

    原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...

  3. (iOS)关于zbar扫描条形码,所搭载的设备

    四个月之前写的,现在发出来. 最近在开发一款程序的时候,功能要求扫描条形码. 现在最流行的扫描条形码的开源代码有zbar和zxing两种,可以支持多种一维和二维码. 之前了解过zbar,所以这次试用z ...

  4. Android 扫描蓝牙设备

    Android扫描蓝牙设备是个异步的过程,核心的步骤为:调用bluetoothAdapter的startDiscovery()进行设备扫描,扫描的结果通过广播接收处理!具体如下: 1.申请相关权限 & ...

  5. Android Studio中常用插件及浅释

    博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园:追风917 插件可以来这个仓库查找:Android Studio Plugins 这里给出几个平时常用到的as插 ...

  6. 怎样使用Android Studio开发Gradle插件

    缘由 首先说明一下为什么会有这篇文章.前段时间,插件化以及热修复的技术非常热,Nuwa热修复的工具NuwaGradle,携程动态载入技术DynamicAPK,还有希望做最轻巧的插件化框架的Small. ...

  7. 转发—Android开发常用的插件及工具

    作者:蓝之风 出处:http://www.cnblogs.com/vaiyanzi/ Android开发常用的插件及工具 1.GitHub,这个不管是做安卓还是其他,只要是开发就必上的网站,也是天朝没 ...

  8. Android Studio安装Genymotion插件

    Android Studio安装Genymotion插件 Eclipse就不介绍了,谷歌都已经放弃Eclipse了,你还在坚持什么. 安装Genymotion 官网:https://www.genym ...

  9. 【Android Studio安装部署系列】二十九、Android Studio安装本地插件(以国际化方法插件AndroidLocalizationer为例)

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 实际开发中,需要用到插件,用来提高效率,这里就以生成国际化strings.xml的插件AndroidLocalizationer为例 ...

随机推荐

  1. 深入理解JS 执行细节

    javascript从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习JS引擎工作机制之前,我们需要引入几个相关的概念:执行环境栈.全局对象.执行环境.变量对象.活动对象.作用域和作用域链等 ...

  2. 【翻译】MongoDB指南/CRUD操作(二)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...

  3. mysql 7下载安装及问题解决

    mysql 7安装及问题解决 一.mysql下载 下载地址:https://www.mysql.com/downloads/ Community (GPL) Downloads MySQL Commu ...

  4. 使用 JavaScript 和 canvas 做精确的像素碰撞检测

    原文地址:Pixel accurate collision detection with Javascript and Canvas 译者:nzbin 我正在开发一个需要再次使用碰撞检测的游戏.我通常 ...

  5. 套用JQuery EasyUI列表显示数据、分页、查询

    声明,本博客从csdn搬到cnblogs博客园了,以前的csdn不再更新,朋友们可以到这儿来找我的文章,更多的文章会发表,谢谢关注! 有时候闲的无聊,看到extjs那么肥大,真想把自己的项目改了,最近 ...

  6. Web安全相关(三):开放重定向(Open Redirection)

    简介 那些通过请求(如查询字符串和表单数据)指定重定向URL的Web程序可能会被篡改,而把用户重定向到外部的恶意URL.这种篡改就被称为开发重定向攻击.   场景分析 假设有一个正规网站http:// ...

  7. css中line-height行高的深入学习

    之前对css中行高line-height的理解还是有些肤浅,深入后才发觉里面包罗万象.学习行高line-height,首先从基本原理开始 (标注该文章转载 http://www.cnblogs.com ...

  8. BPM配置故事之案例12-触发另外流程

    还记得阿海么,对就是之前的那个采购员,他又有了些意见. 阿海:小明,你看现在的流程让大家都这么方便,能不能帮个忙让我也轻松点啊-- 小明:--你有什么麻烦,现在不是已经各个部门自己提交申请了嘛? 阿海 ...

  9. Java集合类--温习笔记

    最近面试发现自己的知识框架有好多问题.明明脑子里知道这个知识点,流程原理也都明白,可就是说不好,不知道是自己表达技能没点,还是确实是自己基础有问题.不管了,再巩固下基础知识总是没错的,反正最近空闲时间 ...

  10. ORACLE从共享池删除指定SQL的执行计划

    Oracle 11g在DBMS_SHARED_POOL包中引入了一个名为PURGE的新存储过程,用于从对象库缓存中刷新特定对象,例如游标,包,序列,触发器等.也就是说可以删除.清理特定SQL的执行计划 ...