QR reader with androidX and firebase












0















I'm trying to do a QR reader with androidX and firebase, the thing is all the information about the changes is new and I'm having problems at making this app work and I think it is because of the build of the app. I'm tried different versions and libraries to use but the problem persists. One of the errors I got is



"Error: Program type already present: android.support.v4.app.INotificationSideChannel"



but there is probably some more (the debugging just mark that)



Gradle



apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.android.qrtest3"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
implementation'com.wonderkiln:camerakit:0.13.1'
implementation'com.github.d-max:spots-dialog:1.1@aar'
}
apply plugin: 'com.google.gms.google-services'


Gradle Project



// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}


Main Activity



package com.example.android.qrtest3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.ml.vision.FirebaseVision;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.wonderkiln.camerakit.CameraKitError;
import com.wonderkiln.camerakit.CameraKitEvent;
import com.wonderkiln.camerakit.CameraKitEventListener;
import com.wonderkiln.camerakit.CameraKitImage;
import com.wonderkiln.camerakit.CameraKitVideo;
import com.wonderkiln.camerakit.CameraView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

CameraView cameraView;
Button btnDetect;

@Override
protected void onResume() {
super.onResume();
cameraView.start();
}

@Override
protected void onPause() {
super.onPause();
cameraView.stop();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

cameraView = (CameraView) findViewById(R.id.cameraview);
btnDetect = (Button) findViewById(R.id.btn_detect);


btnDetect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cameraView.start();
cameraView.captureImage();
}

});

cameraView.addCameraKitListener(new CameraKitEventListener() {
@Override
public void onEvent(CameraKitEvent cameraKitEvent) {

}

@Override
public void onError(CameraKitError cameraKitError) {

}

@Override
public void onImage(CameraKitImage cameraKitImage) {
Bitmap bitmap = cameraKitImage.getBitmap();
bitmap = Bitmap.createScaledBitmap(bitmap, cameraView.getWidth(),cameraView.getHeight(), false);
cameraView.stop();

runDetector(bitmap);
}

@Override
public void onVideo(CameraKitVideo cameraKitVideo) {

}
});

}

private void runDetector(Bitmap bitmap) {
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
FirebaseVisionBarcodeDetectorOptions options = new FirebaseVisionBarcodeDetectorOptions.Builder()
.setBarcodeFormats(
FirebaseVisionBarcode.FORMAT_QR_CODE,
FirebaseVisionBarcode.FORMAT_PDF417
)
.build();
FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options);

detector.detectInImage(image)
.addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
@Override
public void onSuccess(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
processResult(firebaseVisionBarcodes);
}
})

.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});

}

private void processResult(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
for(FirebaseVisionBarcode item : firebaseVisionBarcodes)
{
int value_type = item.getValueType();
switch (value_type)
{
case FirebaseVisionBarcode.TYPE_TEXT:
{
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
builder.setMessage(item.getRawValue());
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
android.support.v7.app.AlertDialog dialog = builder.create();
dialog.show();
}
break;

case FirebaseVisionBarcode.TYPE_URL:
{
//start browse url
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getRawValue()));
startActivity(intent);
}
break;

case FirebaseVisionBarcode.TYPE_CONTACT_INFO:
{
String info = new StringBuilder("Name: ")
.append(item.getContactInfo().getName().getFormattedName())
.append ("n")
.append ("Adress: ")
.append (item.getContactInfo().getAddresses().get(0).getAddressLines())
.append ("n")
.append ("Email: ")
.append (item.getContactInfo().getEmails().get(0).getAddress())
.toString();
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
builder.setMessage(info);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
android.support.v7.app.AlertDialog dialog = builder.create();
dialog.show();
}
break;
default:
break;
}
}
}
}









share|improve this question





























    0















    I'm trying to do a QR reader with androidX and firebase, the thing is all the information about the changes is new and I'm having problems at making this app work and I think it is because of the build of the app. I'm tried different versions and libraries to use but the problem persists. One of the errors I got is



    "Error: Program type already present: android.support.v4.app.INotificationSideChannel"



    but there is probably some more (the debugging just mark that)



    Gradle



    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 28
    defaultConfig {
    applicationId "com.example.android.qrtest3"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    }

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.gms:play-services-ads:16.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

    implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
    implementation'com.wonderkiln:camerakit:0.13.1'
    implementation'com.github.d-max:spots-dialog:1.1@aar'
    }
    apply plugin: 'com.google.gms.google-services'


    Gradle Project



    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

    repositories {
    google()
    jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
    }

    allprojects {
    repositories {
    google()
    jcenter()
    mavenCentral()
    maven {
    url "https://maven.google.com"
    }
    }
    }

    task clean(type: Delete) {
    delete rootProject.buildDir
    }


    Main Activity



    package com.example.android.qrtest3;

    import androidx.appcompat.app.AppCompatActivity;

    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.pm.ActivityInfo;
    import android.graphics.Bitmap;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;

    import com.google.android.gms.tasks.OnFailureListener;
    import com.google.android.gms.tasks.OnSuccessListener;
    import com.google.firebase.ml.vision.FirebaseVision;
    import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
    import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
    import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
    import com.google.firebase.ml.vision.common.FirebaseVisionImage;
    import com.wonderkiln.camerakit.CameraKitError;
    import com.wonderkiln.camerakit.CameraKitEvent;
    import com.wonderkiln.camerakit.CameraKitEventListener;
    import com.wonderkiln.camerakit.CameraKitImage;
    import com.wonderkiln.camerakit.CameraKitVideo;
    import com.wonderkiln.camerakit.CameraView;

    import java.util.List;

    public class MainActivity extends AppCompatActivity {

    CameraView cameraView;
    Button btnDetect;

    @Override
    protected void onResume() {
    super.onResume();
    cameraView.start();
    }

    @Override
    protected void onPause() {
    super.onPause();
    cameraView.stop();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    cameraView = (CameraView) findViewById(R.id.cameraview);
    btnDetect = (Button) findViewById(R.id.btn_detect);


    btnDetect.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    cameraView.start();
    cameraView.captureImage();
    }

    });

    cameraView.addCameraKitListener(new CameraKitEventListener() {
    @Override
    public void onEvent(CameraKitEvent cameraKitEvent) {

    }

    @Override
    public void onError(CameraKitError cameraKitError) {

    }

    @Override
    public void onImage(CameraKitImage cameraKitImage) {
    Bitmap bitmap = cameraKitImage.getBitmap();
    bitmap = Bitmap.createScaledBitmap(bitmap, cameraView.getWidth(),cameraView.getHeight(), false);
    cameraView.stop();

    runDetector(bitmap);
    }

    @Override
    public void onVideo(CameraKitVideo cameraKitVideo) {

    }
    });

    }

    private void runDetector(Bitmap bitmap) {
    FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
    FirebaseVisionBarcodeDetectorOptions options = new FirebaseVisionBarcodeDetectorOptions.Builder()
    .setBarcodeFormats(
    FirebaseVisionBarcode.FORMAT_QR_CODE,
    FirebaseVisionBarcode.FORMAT_PDF417
    )
    .build();
    FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options);

    detector.detectInImage(image)
    .addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
    @Override
    public void onSuccess(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
    processResult(firebaseVisionBarcodes);
    }
    })

    .addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
    Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
    });

    }

    private void processResult(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
    for(FirebaseVisionBarcode item : firebaseVisionBarcodes)
    {
    int value_type = item.getValueType();
    switch (value_type)
    {
    case FirebaseVisionBarcode.TYPE_TEXT:
    {
    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
    builder.setMessage(item.getRawValue());
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
    dialogInterface.dismiss();
    }
    });
    android.support.v7.app.AlertDialog dialog = builder.create();
    dialog.show();
    }
    break;

    case FirebaseVisionBarcode.TYPE_URL:
    {
    //start browse url
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getRawValue()));
    startActivity(intent);
    }
    break;

    case FirebaseVisionBarcode.TYPE_CONTACT_INFO:
    {
    String info = new StringBuilder("Name: ")
    .append(item.getContactInfo().getName().getFormattedName())
    .append ("n")
    .append ("Adress: ")
    .append (item.getContactInfo().getAddresses().get(0).getAddressLines())
    .append ("n")
    .append ("Email: ")
    .append (item.getContactInfo().getEmails().get(0).getAddress())
    .toString();
    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
    builder.setMessage(info);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
    dialogInterface.dismiss();
    }
    });
    android.support.v7.app.AlertDialog dialog = builder.create();
    dialog.show();
    }
    break;
    default:
    break;
    }
    }
    }
    }









    share|improve this question



























      0












      0








      0








      I'm trying to do a QR reader with androidX and firebase, the thing is all the information about the changes is new and I'm having problems at making this app work and I think it is because of the build of the app. I'm tried different versions and libraries to use but the problem persists. One of the errors I got is



      "Error: Program type already present: android.support.v4.app.INotificationSideChannel"



      but there is probably some more (the debugging just mark that)



      Gradle



      apply plugin: 'com.android.application'

      android {
      compileSdkVersion 28
      defaultConfig {
      applicationId "com.example.android.qrtest3"
      minSdkVersion 15
      targetSdkVersion 28
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
      release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
      }
      }

      dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      //noinspection GradleCompatible
      implementation 'com.google.firebase:firebase-core:16.0.5'
      implementation 'com.google.firebase:firebase-messaging:17.3.4'
      implementation 'androidx.appcompat:appcompat:1.0.2'
      implementation 'com.google.android.material:material:1.0.0-rc01'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      implementation 'com.google.android.gms:play-services-ads:16.0.0'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test:runner:1.1.0'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

      implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
      implementation'com.wonderkiln:camerakit:0.13.1'
      implementation'com.github.d-max:spots-dialog:1.1@aar'
      }
      apply plugin: 'com.google.gms.google-services'


      Gradle Project



      // Top-level build file where you can add configuration options common to all sub-projects/modules.

      buildscript {

      repositories {
      google()
      jcenter()
      }
      dependencies {
      classpath 'com.android.tools.build:gradle:3.2.1'
      classpath 'com.google.gms:google-services:4.0.1'

      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
      }
      }

      allprojects {
      repositories {
      google()
      jcenter()
      mavenCentral()
      maven {
      url "https://maven.google.com"
      }
      }
      }

      task clean(type: Delete) {
      delete rootProject.buildDir
      }


      Main Activity



      package com.example.android.qrtest3;

      import androidx.appcompat.app.AppCompatActivity;

      import android.content.DialogInterface;
      import android.content.Intent;
      import android.content.pm.ActivityInfo;
      import android.graphics.Bitmap;
      import android.net.Uri;
      import android.os.Bundle;
      import android.support.annotation.NonNull;
      import android.view.View;
      import android.widget.Button;
      import android.widget.Toast;

      import com.google.android.gms.tasks.OnFailureListener;
      import com.google.android.gms.tasks.OnSuccessListener;
      import com.google.firebase.ml.vision.FirebaseVision;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
      import com.google.firebase.ml.vision.common.FirebaseVisionImage;
      import com.wonderkiln.camerakit.CameraKitError;
      import com.wonderkiln.camerakit.CameraKitEvent;
      import com.wonderkiln.camerakit.CameraKitEventListener;
      import com.wonderkiln.camerakit.CameraKitImage;
      import com.wonderkiln.camerakit.CameraKitVideo;
      import com.wonderkiln.camerakit.CameraView;

      import java.util.List;

      public class MainActivity extends AppCompatActivity {

      CameraView cameraView;
      Button btnDetect;

      @Override
      protected void onResume() {
      super.onResume();
      cameraView.start();
      }

      @Override
      protected void onPause() {
      super.onPause();
      cameraView.stop();
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

      cameraView = (CameraView) findViewById(R.id.cameraview);
      btnDetect = (Button) findViewById(R.id.btn_detect);


      btnDetect.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
      cameraView.start();
      cameraView.captureImage();
      }

      });

      cameraView.addCameraKitListener(new CameraKitEventListener() {
      @Override
      public void onEvent(CameraKitEvent cameraKitEvent) {

      }

      @Override
      public void onError(CameraKitError cameraKitError) {

      }

      @Override
      public void onImage(CameraKitImage cameraKitImage) {
      Bitmap bitmap = cameraKitImage.getBitmap();
      bitmap = Bitmap.createScaledBitmap(bitmap, cameraView.getWidth(),cameraView.getHeight(), false);
      cameraView.stop();

      runDetector(bitmap);
      }

      @Override
      public void onVideo(CameraKitVideo cameraKitVideo) {

      }
      });

      }

      private void runDetector(Bitmap bitmap) {
      FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
      FirebaseVisionBarcodeDetectorOptions options = new FirebaseVisionBarcodeDetectorOptions.Builder()
      .setBarcodeFormats(
      FirebaseVisionBarcode.FORMAT_QR_CODE,
      FirebaseVisionBarcode.FORMAT_PDF417
      )
      .build();
      FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options);

      detector.detectInImage(image)
      .addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
      @Override
      public void onSuccess(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
      processResult(firebaseVisionBarcodes);
      }
      })

      .addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
      Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
      }
      });

      }

      private void processResult(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
      for(FirebaseVisionBarcode item : firebaseVisionBarcodes)
      {
      int value_type = item.getValueType();
      switch (value_type)
      {
      case FirebaseVisionBarcode.TYPE_TEXT:
      {
      android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
      builder.setMessage(item.getRawValue());
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
      dialogInterface.dismiss();
      }
      });
      android.support.v7.app.AlertDialog dialog = builder.create();
      dialog.show();
      }
      break;

      case FirebaseVisionBarcode.TYPE_URL:
      {
      //start browse url
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getRawValue()));
      startActivity(intent);
      }
      break;

      case FirebaseVisionBarcode.TYPE_CONTACT_INFO:
      {
      String info = new StringBuilder("Name: ")
      .append(item.getContactInfo().getName().getFormattedName())
      .append ("n")
      .append ("Adress: ")
      .append (item.getContactInfo().getAddresses().get(0).getAddressLines())
      .append ("n")
      .append ("Email: ")
      .append (item.getContactInfo().getEmails().get(0).getAddress())
      .toString();
      android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
      builder.setMessage(info);
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
      dialogInterface.dismiss();
      }
      });
      android.support.v7.app.AlertDialog dialog = builder.create();
      dialog.show();
      }
      break;
      default:
      break;
      }
      }
      }
      }









      share|improve this question
















      I'm trying to do a QR reader with androidX and firebase, the thing is all the information about the changes is new and I'm having problems at making this app work and I think it is because of the build of the app. I'm tried different versions and libraries to use but the problem persists. One of the errors I got is



      "Error: Program type already present: android.support.v4.app.INotificationSideChannel"



      but there is probably some more (the debugging just mark that)



      Gradle



      apply plugin: 'com.android.application'

      android {
      compileSdkVersion 28
      defaultConfig {
      applicationId "com.example.android.qrtest3"
      minSdkVersion 15
      targetSdkVersion 28
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
      release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
      }
      }

      dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      //noinspection GradleCompatible
      implementation 'com.google.firebase:firebase-core:16.0.5'
      implementation 'com.google.firebase:firebase-messaging:17.3.4'
      implementation 'androidx.appcompat:appcompat:1.0.2'
      implementation 'com.google.android.material:material:1.0.0-rc01'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      implementation 'com.google.android.gms:play-services-ads:16.0.0'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test:runner:1.1.0'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

      implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
      implementation'com.wonderkiln:camerakit:0.13.1'
      implementation'com.github.d-max:spots-dialog:1.1@aar'
      }
      apply plugin: 'com.google.gms.google-services'


      Gradle Project



      // Top-level build file where you can add configuration options common to all sub-projects/modules.

      buildscript {

      repositories {
      google()
      jcenter()
      }
      dependencies {
      classpath 'com.android.tools.build:gradle:3.2.1'
      classpath 'com.google.gms:google-services:4.0.1'

      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
      }
      }

      allprojects {
      repositories {
      google()
      jcenter()
      mavenCentral()
      maven {
      url "https://maven.google.com"
      }
      }
      }

      task clean(type: Delete) {
      delete rootProject.buildDir
      }


      Main Activity



      package com.example.android.qrtest3;

      import androidx.appcompat.app.AppCompatActivity;

      import android.content.DialogInterface;
      import android.content.Intent;
      import android.content.pm.ActivityInfo;
      import android.graphics.Bitmap;
      import android.net.Uri;
      import android.os.Bundle;
      import android.support.annotation.NonNull;
      import android.view.View;
      import android.widget.Button;
      import android.widget.Toast;

      import com.google.android.gms.tasks.OnFailureListener;
      import com.google.android.gms.tasks.OnSuccessListener;
      import com.google.firebase.ml.vision.FirebaseVision;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector;
      import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions;
      import com.google.firebase.ml.vision.common.FirebaseVisionImage;
      import com.wonderkiln.camerakit.CameraKitError;
      import com.wonderkiln.camerakit.CameraKitEvent;
      import com.wonderkiln.camerakit.CameraKitEventListener;
      import com.wonderkiln.camerakit.CameraKitImage;
      import com.wonderkiln.camerakit.CameraKitVideo;
      import com.wonderkiln.camerakit.CameraView;

      import java.util.List;

      public class MainActivity extends AppCompatActivity {

      CameraView cameraView;
      Button btnDetect;

      @Override
      protected void onResume() {
      super.onResume();
      cameraView.start();
      }

      @Override
      protected void onPause() {
      super.onPause();
      cameraView.stop();
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

      cameraView = (CameraView) findViewById(R.id.cameraview);
      btnDetect = (Button) findViewById(R.id.btn_detect);


      btnDetect.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
      cameraView.start();
      cameraView.captureImage();
      }

      });

      cameraView.addCameraKitListener(new CameraKitEventListener() {
      @Override
      public void onEvent(CameraKitEvent cameraKitEvent) {

      }

      @Override
      public void onError(CameraKitError cameraKitError) {

      }

      @Override
      public void onImage(CameraKitImage cameraKitImage) {
      Bitmap bitmap = cameraKitImage.getBitmap();
      bitmap = Bitmap.createScaledBitmap(bitmap, cameraView.getWidth(),cameraView.getHeight(), false);
      cameraView.stop();

      runDetector(bitmap);
      }

      @Override
      public void onVideo(CameraKitVideo cameraKitVideo) {

      }
      });

      }

      private void runDetector(Bitmap bitmap) {
      FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
      FirebaseVisionBarcodeDetectorOptions options = new FirebaseVisionBarcodeDetectorOptions.Builder()
      .setBarcodeFormats(
      FirebaseVisionBarcode.FORMAT_QR_CODE,
      FirebaseVisionBarcode.FORMAT_PDF417
      )
      .build();
      FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options);

      detector.detectInImage(image)
      .addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionBarcode>>() {
      @Override
      public void onSuccess(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
      processResult(firebaseVisionBarcodes);
      }
      })

      .addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
      Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
      }
      });

      }

      private void processResult(List<FirebaseVisionBarcode> firebaseVisionBarcodes) {
      for(FirebaseVisionBarcode item : firebaseVisionBarcodes)
      {
      int value_type = item.getValueType();
      switch (value_type)
      {
      case FirebaseVisionBarcode.TYPE_TEXT:
      {
      android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
      builder.setMessage(item.getRawValue());
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
      dialogInterface.dismiss();
      }
      });
      android.support.v7.app.AlertDialog dialog = builder.create();
      dialog.show();
      }
      break;

      case FirebaseVisionBarcode.TYPE_URL:
      {
      //start browse url
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getRawValue()));
      startActivity(intent);
      }
      break;

      case FirebaseVisionBarcode.TYPE_CONTACT_INFO:
      {
      String info = new StringBuilder("Name: ")
      .append(item.getContactInfo().getName().getFormattedName())
      .append ("n")
      .append ("Adress: ")
      .append (item.getContactInfo().getAddresses().get(0).getAddressLines())
      .append ("n")
      .append ("Email: ")
      .append (item.getContactInfo().getEmails().get(0).getAddress())
      .toString();
      android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
      builder.setMessage(info);
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
      dialogInterface.dismiss();
      }
      });
      android.support.v7.app.AlertDialog dialog = builder.create();
      dialog.show();
      }
      break;
      default:
      break;
      }
      }
      }
      }






      android firebase qr-code androidx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 14:35









      Frank van Puffelen

      243k29387415




      243k29387415










      asked Nov 16 '18 at 8:59









      Santiago BozziSantiago Bozzi

      248




      248
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The thing was I needed to fully migrate to AndroidX (



          implementation 'com.google.android.material:material:1.0.0-rc01'
          implementation 'com.android.support.constraint:constraint-layout:1.1.3'
          implementation 'com.google.android.gms:play-services-ads:16.0.0'


          importing the right things and changing



          android.support.v7.app.AlertDialog to AlertDialog.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334457%2fqr-reader-with-androidx-and-firebase%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The thing was I needed to fully migrate to AndroidX (



            implementation 'com.google.android.material:material:1.0.0-rc01'
            implementation 'com.android.support.constraint:constraint-layout:1.1.3'
            implementation 'com.google.android.gms:play-services-ads:16.0.0'


            importing the right things and changing



            android.support.v7.app.AlertDialog to AlertDialog.






            share|improve this answer




























              0














              The thing was I needed to fully migrate to AndroidX (



              implementation 'com.google.android.material:material:1.0.0-rc01'
              implementation 'com.android.support.constraint:constraint-layout:1.1.3'
              implementation 'com.google.android.gms:play-services-ads:16.0.0'


              importing the right things and changing



              android.support.v7.app.AlertDialog to AlertDialog.






              share|improve this answer


























                0












                0








                0







                The thing was I needed to fully migrate to AndroidX (



                implementation 'com.google.android.material:material:1.0.0-rc01'
                implementation 'com.android.support.constraint:constraint-layout:1.1.3'
                implementation 'com.google.android.gms:play-services-ads:16.0.0'


                importing the right things and changing



                android.support.v7.app.AlertDialog to AlertDialog.






                share|improve this answer













                The thing was I needed to fully migrate to AndroidX (



                implementation 'com.google.android.material:material:1.0.0-rc01'
                implementation 'com.android.support.constraint:constraint-layout:1.1.3'
                implementation 'com.google.android.gms:play-services-ads:16.0.0'


                importing the right things and changing



                android.support.v7.app.AlertDialog to AlertDialog.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 17 '18 at 6:27









                Santiago BozziSantiago Bozzi

                248




                248
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334457%2fqr-reader-with-androidx-and-firebase%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python