0
私はZxingバーコードスキャナを統合したアンドロイドアプリを構築しています。カメラが開き、赤線は表示されますが、データはスキャンされません。 フラグメントのコードは次のとおりです。v4.app.fragmentを使用しました。ここでAndroid/Zxing:ZxingスキャナはonActivityResultメソッドを起動しません
public class AddItem extends Fragment{
public AddItem() {
// Required empty public constructor
}
String Idno;
String Name;
String Brand;
String Cost;
String Storeid;
String Date;
String Type;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_add_item, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ImageButton button=(ImageButton)getView().findViewById(R.id.img);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IntentIntegrator.forSupportFragment(AddItem.this).setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES).initiateScan();
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
final EditText idno=(EditText)getView().findViewById(R.id.IdNum);
final EditText title=(EditText)getView().findViewById(R.id.title);
final EditText brand=(EditText)getView().findViewById(R.id.brand);
final EditText cost=(EditText)getView().findViewById(R.id.price);
final EditText store=(EditText)getView().findViewById(R.id.storeid);
final EditText date=(EditText)getView().findViewById(R.id.date);
if (scanningResult != null) {
//we have a result
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
Toast toast = Toast.makeText(getActivity(),scanContent, Toast.LENGTH_SHORT);
toast.show();
// display it on screenformatTxt.setText("FORMAT: " + scanFormat);
idno.setText(scanContent);
}else{
Toast toast = Toast.makeText(getActivity(),"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
私のアプリのGradleのである:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.strokx.user.stockmanager"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:24.2.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-crash:9.4.0'
compile 'com.firebase:firebase-client-android:2.4.0'
compile 'com.journeyapps:zxing-android-embedded:[email protected]'
compile 'com.google.zxing:core:3.2.1'
compile 'com.firebaseui:firebase-ui:0.4.3'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
そして、ここでは私のManifest.xmlです:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.strokx.user.stockmanager">
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk tools:overrideLibrary="com.firebase.ui,com.firebase.ui.auth,com.facebook,android.support.customtabs"/>
<application
android:allowBackup="true"
android:icon="@drawable/purchase_icon"
android:label="@string/app_name"
android:name=".StockManager"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
</manifest>
を動作するかどうか、私に教えてください? –
なしカメラは何もスキャンしません。戻るボタンを押すと、スキャンされたデータがない場合のelseケースが表示されます –