so schaut mein Java file und xml file aus. Natürlich habe ich IntentIntegrator.java und IntentResult.java auch in Projekt
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public static final String EXTRA_BARCODE = "extraBarcode";
public static final String EXTRA_FORMAT = "extraFormat";
public boolean mainIsOpen = true;
private IntentIntegrator mIntentIntegrator;
public final static String EXTRA_MESSAGE = "com.example.pricescannerapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mIntentIntegrator = new IntentIntegrator(this);
}
public void onClick(View view) {
this.mIntentIntegrator.initiateScan();
}
public void showProducts(View view) {
setContentView(R.layout.products);
mainIsOpen = false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mainIsOpen == false) {
mainIsOpen = true;
setContentView(R.layout.activity_main);
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, intent);
if (scanResult != null) {
String barcode;
String type;
EditText etBarcode = null;
EditText etTyp = null;
barcode = scanResult.getContents();
if (barcode != null) {
etBarcode = (EditText) findViewById(R.id.etBarcode);
etBarcode.setText(barcode);
} else {
etBarcode.setText(R.string.result_failed);
}
type = scanResult.getFormatName();
if (type != null) {
etTyp = (EditText) findViewById(R.id.etType);
etTyp.setText(type);
} else {
etTyp.setText(R.string.result_failed);
}
}
}
}
[XML]
<TextView
android:id="@+id/barcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/barcode"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<EditText
android:id="@+id/etBarcode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/barcode_place" />
<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/type"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/type_place" />
<Button
android:id="@+id/buttonScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:text="@string/scanStart" />
<Button
android:id="@+id/buttonProdukte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="showProducts"
android:text="@string/showProducts" />
[/XML]
[XML]<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">PriceScannerApp</string>
<string name="action_settings">Settings</string>
<string name="start_scan">Scan product</string>
<string name="result_failed">No barcode found</string>
<string name="save">save</string>
<string name = "barcode">Barcode</string>
<string name = "type">Type</string>
<string name="barcode_place">Barcode</string>
<string name="type_place">Type</string>
<string name="einkauf">Einkauf</string>
<string name = "scanStart">Scan Start</string>
<string name = "showProducts"> Show Products</string>
<string name="title_activity_display_barcode">DisplayBarcode</string>
[/XML]
wenn ich Programm ausführe und auf scan drucken bekomme ich folgende Meldung, wenn ich auf ok Klicke passiert trotzdem nicht. es wird nichts runtergeladen. was kann ich tun?
meine zweite Frage bezieht sich auf diesem Teil vom Code
public static final String EXTRA_FORMAT = "extraFormat";
public final static String EXTRA_MESSAGE = "com.example.pricescannerapp.MESSAGE";```
das ist nicht von mir, hat ein Freund von mir empfohlen, aber leider habe ich nicht verstanden wie ich die nutzen kann.