Android 扫描条形码(Zxing插件)
使用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插件)的更多相关文章
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
Android 高手进阶(21) 版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...
- 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错
原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...
- (iOS)关于zbar扫描条形码,所搭载的设备
四个月之前写的,现在发出来. 最近在开发一款程序的时候,功能要求扫描条形码. 现在最流行的扫描条形码的开源代码有zbar和zxing两种,可以支持多种一维和二维码. 之前了解过zbar,所以这次试用z ...
- Android 扫描蓝牙设备
Android扫描蓝牙设备是个异步的过程,核心的步骤为:调用bluetoothAdapter的startDiscovery()进行设备扫描,扫描的结果通过广播接收处理!具体如下: 1.申请相关权限 & ...
- Android Studio中常用插件及浅释
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园:追风917 插件可以来这个仓库查找:Android Studio Plugins 这里给出几个平时常用到的as插 ...
- 怎样使用Android Studio开发Gradle插件
缘由 首先说明一下为什么会有这篇文章.前段时间,插件化以及热修复的技术非常热,Nuwa热修复的工具NuwaGradle,携程动态载入技术DynamicAPK,还有希望做最轻巧的插件化框架的Small. ...
- 转发—Android开发常用的插件及工具
作者:蓝之风 出处:http://www.cnblogs.com/vaiyanzi/ Android开发常用的插件及工具 1.GitHub,这个不管是做安卓还是其他,只要是开发就必上的网站,也是天朝没 ...
- Android Studio安装Genymotion插件
Android Studio安装Genymotion插件 Eclipse就不介绍了,谷歌都已经放弃Eclipse了,你还在坚持什么. 安装Genymotion 官网:https://www.genym ...
- 【Android Studio安装部署系列】二十九、Android Studio安装本地插件(以国际化方法插件AndroidLocalizationer为例)
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 实际开发中,需要用到插件,用来提高效率,这里就以生成国际化strings.xml的插件AndroidLocalizationer为例 ...
随机推荐
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- ASP.NET Core应用针对静态文件请求的处理[3]: StaticFileMiddleware中间件如何处理针对文件请求
我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的介绍,从提供的功能和特性的角度对这个名为StaticFileMidd ...
- 【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理
干货!详述Python NLTK下如何使用stanford NLP工具包 作者:白宁超 2016年11月6日19:28:43 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的 ...
- dagger2系列之依赖方式dependencies、包含方式(从属方式)SubComponent
本篇是实战文章,从代码的角度分析这两种方式.本文参考自下列文章: http://www.jianshu.com/p/1d42d2e6f4a5 http://www.jianshu.com/p/94d4 ...
- ASP.NET MVC关于Ajax以及Jquery的无限级联动
---恢复内容开始--- 第一次发表博文,发表博文的目的是巩固自己的技术,也能够共享给大家.写的不好的地方,希望大家多给给意见.老司机勿喷 数据结构() NewsTypeId 新闻ID, NewsTy ...
- css样式之border-image
border-image-source 属性设置边框的图片的路径[none | <image>] div { border: 20px solid #000; border-image-s ...
- iOS之解决崩溃Collection <__NSArrayM: 0xb550c30> was mutated while being enumerated.
崩溃提示:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CAL ...
- Create a bridge using a tagged vlan (8021.q) interface
SOLUTION VERIFIED April 27 2013 KB26727 Environment Red Hat Enterprise Linux 5 Red Hat Enterprise Li ...
- EChart系列:在echart3中使用百度地图扩展之后,如何获取到百度地图对象
最近做项目想要在百度地图上叠加显示echart的散点图,然后根据地图的缩放等级和区域范围要显示不同的散点图,这中间折腾了好久.功能要求包括: (1)底图使用百度地图: (2)可以在地图上叠加显示ech ...
- CentOS 6.5安装Node.js, npm
CentOS上可以通过下载*.tar.gz安装包的方式自己解压缩.编译的方式安装,同时还可以采用EPEL的方式安装: Node.js and npm are available from the Fe ...