所以我这样做了2天仍然无法正常工作。我尝试了一些github建议和那些堆栈溢出,但都没有为我工作,谷歌视觉和斑马线(ZXing)有人可以帮助我吗?它显示了一个刺激性的白色屏幕,我在版本4.4.4和4.1.2中尝试了这些。是我的代码,我现在正在使用Zxing。
这是我的班级,其中按钮的数量是阵容。从这里我去了扫描仪所在的班级,所以我可以扫描该项目,然后从那里我将做另一个功能。目前我的目标是能够扫描QR码并获得其输入。我已经找到了一些关于如何获得输入的例子,所以这不是问题。 btu是的它没有显示!
Normal.java
public class Normal extends AppCompatActivity {
Button suite, normal, room1, room2, room3, room4, room5, room6, room7, room8, room9, room10;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private DatabaseReference mFirebaseDatabase1;
private FirebaseDatabase mFirebaseInstance;
//FIREBASE AUTH FIELDS
DatabaseReference mSearchedLocationReference;
DatabaseReference mSearchedLocationReference1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_normal);
mFirebaseInstance = FirebaseDatabase.getInstance();
//FIREBASE
mFirebaseDatabase1 = mFirebaseInstance.getReference("Rooms");
//FIREBASE PINPOINT
//DRAWER LAYOUT
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
//navigation Drawer
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav_menu);
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case (R.id.nav_logout):
Intent accountActivity4 = new Intent(getApplicationContext(), login1.class);
finish();
startActivity(accountActivity4);
break;
}
return true;
}
});
//Navigation Drawer
//ASSIGN ID's
room1 = (Button) findViewById(R.id.room2);
room2 = (Button) findViewById(R.id.room3);
room3 = (Button) findViewById(R.id.room4);
room4 = (Button) findViewById(R.id.room5);
room5 = (Button) findViewById(R.id.room6);
room6 = (Button) findViewById(R.id.room7);
room7 = (Button) findViewById(R.id.room8);
room8 = (Button) findViewById(R.id.room9);
room9 = (Button) findViewById(R.id.room10);
room10 = (Button) findViewById(R.id.room11);
//ASSIGN ID's
suite = (Button) findViewById(R.id.button2);
normal = (Button) findViewById(R.id.button);
suite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent next = new Intent(Normal.this, Suite.class);
startActivity(next);
}
});
normal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent next1 = new Intent(Normal.this, Normal.class);
startActivity(next1);
}
});
room1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Normal.this, room2.class));
}
});
room2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
});
room5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Normal.this, room5.class));
}
});
mSearchedLocationReference.addValueEventListener(new ValueEventListener() { //attach listener
@Override
public void onDataChange(DataSnapshot dataSnapshot) { //something changed!
for (DataSnapshot locationSnapshot : dataSnapshot.getChildren()) {
String location = locationSnapshot.getValue().toString();
Log.d("Locations updated", "location: " + location); //log
if ( location.equals("Green")){
room1.setBackgroundColor(Color.GREEN);
}else if ( location.equals("Red")){
room1.setBackgroundColor(Color.RED);
}
else{
room1.setBackgroundColor(Color.YELLOW);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) { //update UI here if error occurred.
}
});
mSearchedLocationReference1.addValueEventListener(new ValueEventListener() { //attach listener
@Override
public void onDataChange(DataSnapshot dataSnapshot) { //something changed!
for (DataSnapshot locationSnapshot : dataSnapshot.getChildren()) {
String location = locationSnapshot.getValue().toString();
Log.d("Locations updated", "location: " + location); //log
if ( location.equals("Green")){
room2.setBackgroundColor(Color.GREEN);
}else if ( location.equals("Red")){
room2.setBackgroundColor(Color.RED);
}
else{
room2.setBackgroundColor(Color.YELLOW);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) { //update UI here if error occurred.
}
});
}
}
whenever i click room1, it won't got to the room2 class where I put the scanner:
room2.class
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class room2 extends AppCompatActivity implements ZXingScannerView.ResultHandler{
private ZXingScannerView zXingScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room2);
}
public void scan(View view){
zXingScannerView =new ZXingScannerView(getApplicationContext());
setContentView(zXingScannerView);
zXingScannerView.setResultHandler(this);
zXingScannerView.startCamera();
}
@Override
protected void onPause() {
super.onPause();
zXingScannerView.stopCamera();
}
@Override
public void handleResult(Result result) {
Toast.makeText(getApplicationContext(),result.getText(),Toast.LENGTH_SHORT).show();
}
}
这是我的清单,因为我一直在尝试这两个,所以它有服务愿景,但确实要求获得相机的许可。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chanty.hoteltwoway">
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication" >
<activity android:name=".login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".Room" />
<activity android:name=".Suite" />
<activity android:name=".Normal" />
<activity android:name=".rooms.room1" />
<activity android:name=".rooms.room2" />
<activity android:name=".rooms.room3" />
<activity android:name=".rooms.room5" />
<activity android:name=".rooms.room6" />
<activity android:name=".rooms.room7" />
<activity android:name=".rooms.room8" />
<activity android:name=".rooms.room10" />
<activity android:name=".suites.suite1" />
<activity android:name=".suites.suite2" />
<activity android:name=".suites.suite3" />
<activity android:name=".suites.suite4" />
<activity android:name=".suites.suite5" />
<activity android:name=".suites.suite6" />
<activity android:name=".suites.suite7" />
<activity android:name=".suites.suite9" />
<activity android:name=".suites.suite8" />
<activity android:name=".suites.suite10" />
<activity android:name=".login1" />
<activity android:name=".MainActivity1" />
<activity android:name=".login2" />
<activity android:name=".Room1" />
<activity android:name=".Normal1" />
<activity android:name=".Suite1" />
<activity android:name=".suprooms.suproom1" />
<activity android:name=".suprooms.suproom2" />
<activity android:name=".suprooms.suproom3" />
<activity android:name=".suprooms.suproom4" />
<activity android:name=".suprooms.suproom5" />
<activity android:name=".suprooms.suproom6" />
<activity android:name=".suprooms.suproom7" />
<activity android:name=".suprooms.suproom8" />
<activity android:name=".suprooms.suproom9" />
<activity android:name=".suprooms.suproom10" />
<activity android:name=".supsuites.supsuite1"></activity>
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode"/>
</application>
</manifest>
很多依赖,因为是的,我从第1天起就开始测试 这是我的gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.chanty.hoteltwoway"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'me.dm7.barcodescanner:zxing:1.7.2'
compile 'com.google.android.gms:play-services-vision:10.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:26.+'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.google.firebase:firebase-core:10.0.1'
testCompile 'junit:junit:4.12'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-service
我尝试根据某些来源降级斑马线依赖关系以便它可能有效。但是,它不起作用,你们能帮助我弄清楚我做错了什么吗?
答案 0 :(得分:0)
尝试启动另一个项目。从您的计划的核心构建。 github教程为您提供了正确的源代码?先测试一下。然后从那里了解他们如何实现它,然后慢慢将其应用到您的程序中。这是一个很好的source开始。