标签:set cti man pad ports 结果 package 继承 read
权限:
<uses-permission
android:name="android.permission.CAMERA"/>
<uses-permission
android:name="READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" />
在AndroidManifest中添加两行代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sir.douyu">
<uses-permission
android:name="android.permission.CAMERA"/>
<uses-permission
android:name="READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".GuidePage">
</activity>
<activity
android:name=".ScanActivity"
android:screenOrientation="portrait" />
</application>
</manifest>
如果想要竖屏显示需要新建一个空的activity继承CaptureActivity:
public class ScanActivity extends CaptureActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
在点击事件中:
@Override
public void onClick(View v) {
IntentIntegrator intentIntegrator = new IntentIntegrator(getActivity());
intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
intentIntegrator.setCaptureActivity(ScanActivity.class);
intentIntegrator.setPrompt("请扫描二维码");//底部的提示文字,设为""可以置空
intentIntegrator.setCameraId(0);//前置或者后置摄像头
intentIntegrator.setBeepEnabled(false); //扫描成功的「哔哔」声,默认开启
intentIntegrator.setBarcodeImageEnabled(true);//是否保留扫码成功时候的截图
intentIntegrator.initiateScan();
}
//继续在下面写上对结果的处理:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
if(scanResult!=null){
String result = scanResult.getContents();
Log.e("HYN",result);
Toast.makeText(getContext(), result, Toast.LENGTH_SHORT).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
标签:set cti man pad ports 结果 package 继承 read
原文地址:http://www.cnblogs.com/98k98k/p/7929591.html