I have a Xamarin Forms 2.0 application that uses ZXing.Net.Mobile and ZXing.Net.Mobile.Forms version 2.0.3.1. I'm trying to build a simple QR code scanner, but whenever I launch the ZXingScannerPage on Android I can see the default overlay (with the text and the red line) but I don't see the output of the camera so I can't actually scan anything. I have already listed the Camera permission in my AndroidManifest:
<uses-permission android:name="android.permission.CAMERA" />
I tried the sample code from the readme: https://github.com/Redth/ZXing.Net.Mobile as well as from their Samples/Forms project. I now have this code:
private async void OnScanQrClicked(object sender, EventArgs e)
{
_scannerPage = new ZXingScannerPage();
_scannerPage.OnScanResult += HandleScanResult;
await Navigation.PushAsync(_scannerPage);
}
private void HandleScanResult(Result result)
{
_scannerPage.IsScanning = false;
Device.BeginInvokeOnMainThread(() =>
{
Navigation.PopAsync();
DisplayAlert("Scanned code", result.Text, "OK");
});
}
Some more specs: I'm running Android 5.1 on a Moto G (v1).
Why am I not seeing the output of the camera?
I fixed it by getting rid of ZXing.Net.Mobile.Forms and downgrading ZXing.Net.Mobile from 2.0 to 1.5. I had to change my implementation, but that was relatively easy.
Another thing people may look at in the future (I didn't try it) is adding the flashlight permission: https://github.com/Redth/ZXing.Net.Mobile/issues/227.
Related
I am using quagga.js for barcode scanning and decoding it works perfectly in chrome and normal browsers. However it doesn't seem to want to work in an android webview app that displays the exact same webpage. Does anyone know why that could be?
I tried having the webview app ask for the user's camera permission on the first load up of the app but it doesn't want to give the prompt.
I added the following to my manifest then added the code below that inside my webchromeclient.
uses-permission android:name="android.permission.RESOURCE_VIDEO_CAPTURE"
#Override
public void onPermissionRequest(final PermissionRequest request) {
final String[] requestedResources = request.getResources();
for (String r : requestedResources) {
if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
request.grant(new String[]{PermissionRequest.RESOURCE_VIDEO_CAPTURE});
break;
}
}
}
I've been trying to print with Brother Print SDK 3.5.1 on Android 8.1.0. I keep getting ERROR_WRONG_LABEL.
This is the code I use
void printPdf() {
// Specify printer
final Printer printer = new Printer();
PrinterInfo settings = printer.getPrinterInfo();
settings.printerModel = PrinterInfo.Model.QL_810W;
settings.port = PrinterInfo.Port.NET;
settings.ipAddress = "192.168.1.73";
settings.workPath = "storage/emulated/0/Download/";
// Print Settings
settings.labelNameIndex = LabelInfo.QL700.W62RB.ordinal();
settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
settings.orientation = PrinterInfo.Orientation.PORTRAIT;
settings.isAutoCut = true;
printer.setPrinterInfo(settings);
// Connect, then print
new Thread(new Runnable() {
#Override
public void run() {
if (printer.startCommunication()) {
PrinterStatus result = printer.printPdfFile("/storage/emulated/0/Download/hello world red.pdf", 1);
if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
Log.d("TAG", "ERROR - " + result.errorCode);
}
printer.endCommunication();
}
}
}).start();
}
My printer model is QL-810W and I use the black and red W62 roll.
I've tried the Sample Application, where setting W62RB in labelNameIndex prints fine.
Changing the roll for different one with different width didn't help.
I've also tried iterating over numbers 0 to 50 and using them as labelNameIndex.
Based on this thread, I thought that the issue may be in specifying the workPath attribute. Setting workPath to getContext().getCacheDir().getPath() results in ERROR_OUT_OF_MEMORY instead of ERROR_WRONG_LABEL. Not specifying workPath and adding <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> to AndroidManifest.xml results in ERROR_WRONG_LABEL
EDIT
I've modified the Brother Sample app and uploaded it to GitHub. The app now launches Activity_PrintPdf.java by default where I inserted my printing code with hardcoded values at the beginning of onCreate method - this works fine and prints the PDF file as expected.
Then I created a new Empty Activity project in Android Studio, copy pasted the library, added the imports to build.gradle and copy pasted the permissions into AndroidManifest.xml. Then I copy pasted the printing code at the beginning of onCreate method in MainActivity.java. Running the app results in ERROR_WRONG_LABEL.
This is the modified working example app and this is the one that results in the error. I want to use the code as native module that I call from my React Native app, so it's important that I manage to set up the printing code from scratch rather than modifying the existing example app.
EDIT 2
I've inspected the library with a debugger: when executing printer.setPrinterInfo(mPrinterInfo) the library internally calls private boolean createWorkPath(String dirPath) of Printer object. On return from this method, the debugger shows Source code doesn't match the bytecode and seems to forget the created directory. This also internally sets mResult.errorCode = ErrorCode.ERROR_WORKPATH_NOT_SET. However, instead of rising any error here the code just silently proceeds, which later results in ERROR_WRONG_LABEL when trying to print. Running the same code snipper in the modified Sample app works fine.
I'd be grateful if you could help or suggest what to try next.
Thank you!
I've now fixed the issue, which was that the Brother library silently failed to create a temporarily folder and instead of reporting an error, it continued and failed later to read the label information. Based on this thread, it is now required to specify runtime file read and write permissions as opposed to the compile-time ones in AndroidManifest.xml.
Adding
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
at the beginning of onCreate before the printing code fixed the issue.
Trying to get a simple button to play a simple string in using TTS in Xamarin.
Some methods we have tried are
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/text-to-speech/#Creating_the_Interface
https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-7-Plugins-for-Xamarin-and-Windows
The second one is as follows, after adding the plugin to the project and the Android and iOS levels.
using System;
using Xamarin.Forms;
using Plugin.TextToSpeech;
namespace AppOne
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void btnHelp_Clicked(object sender, EventArgs e)
{
CrossTextToSpeech.Current.Speak("Help");
}
}
}
Break point was used to check to see if the line was ever run, it was.
Will this method not work with 2017 and we have to use 2015?
We also are using "Live Player" for testing, could that be an issue?
We have used multiple devices including LG G3, SAMSUNG S2 tablet, and a couple other Andriod devices of friends.
Since the recent update for Codename one any barcode scanning seems to be broken.
On android the camera appears and scans the code but nothing happens when it returns to the app (that is none of the 3 callback functions are triggered).
On iOS the camera window doesn't even appear.
I'm using this library since it doesn't rely on an installed scanning app:
https://github.com/littlemonkeyltd/QRScanner
I had thought the inbuilt scanning functionality may have been removed and passed to this library, so I tried to include that too:
https://github.com/codenameone/cn1-codescan
However it still isn't working on Android. IOS refuses to build with the cn1-codescan library included.
Pretty sure this was all working last week, or the week before.
my code looks like this:
Log.p("Scanning QR code");
QRScanner.scanQRCode(new ScanResult() {
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
Log.p("QR result:"+contents);
QRResult(contents, formatName, rawBytes);
}
public void scanCanceled() {
Log.p("scan canceled");
}
public void scanError(int errorCode, String message) {
Log.p("error during scan: " + message);
scanFailed();
}
});
edit:
Here are the android build hints added to codenameone_setting.properties when I add the libraries in:
codename1.arg.android.xapplication=<activity android\:name\="com.dm.zbar.android.scanner.ZBarScannerActivity" android\:screenOrientation\="landscape" android\:label\="#string/app_name" />
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.CAMERA"/><uses-feature android\:name\="android.hardware.camera" android\:required\="false"/>
codename1.arg.android.proguardKeep=\ -keep class net.sourceforge.zbar.** {*;}
If you build against the "latest" barcode scanning should work. I'm assuming that you built against 3.5 and not the latest. It's possible that the regression in barcode scanning got into 3.5, this we verified that barcode/qr code scanning works with the latest on the build servers.
Recently I went thru the code for accessing the camera using flash ActionScript3 and I have tested the code in iMac machine, iPhone and Android.Now based on this, I am developing an application for Android which includes the accessibility of the front camera. Now my Problem is I dont know how to access the front camera? We should use some other code or should we specify which camera should be accessed? First of all, can we access the front camera thru flash?
I made a simple android app. Here is the code for selecting camera window
public class SelectCameraAlertAndroid extends StartAlertAndroid_design{
public function SelectCameraAlertAndroid() {
frontCameraButton.addEventListener(MouseEvent.CLICK, onFrontCamera);
backCameraButton.addEventListener(MouseEvent.CLICK, onBackCamera);
}
private function onFrontCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("1");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
private function onBackCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("0");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
}
Not true. You can access the front camera on Android.
The only problem is that you don't get to use the CameraUI(pretty sure).
var camera = Camera.getCamera("1");
camera.setMode(stage.stageWidth, stage.stageHeight, 30, true);
var video:Video = new Video(stage.stageWidth, stage.stageHeight);
video.attachCamera(camera);
addChild(video);
Note: This answer is outdated. Please refer to the other answers for updated information.
Currently, AIR only supports access to the primary camera on an Android device.
http://forums.adobe.com/thread/849983
Official documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"On Android devices, you can only access the rear-facing camera."