HTML5 Cordova App Blob problems on Blackberry Z10 Android - android

I have a very hard problem :-(
I try to deploy an Android App based on Ionic and Cordova. The App takes a picture and upload it to a server, sounds easy.
BUT on Blackberrys Z10 Android I got a Problem creating the Blob for Uploading :-(
Code Snippets
var imgBlob = $helper.createBlob(this.result, "image/jpeg");
var fd = new FormData();
fd.append('photo', imgBlob, file.name);
fd.append('attachedData', attachedData);
BaasBox.uploadFile(fd).done(function (result) {}
$helper.createBlob is like
self.createBlob = function(data, datatype)
{
var out;
try {
out = new Blob([data], {type: datatype});
console.debug("case 1");
}
catch (e) {
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if (e.name == 'TypeError' && window.BlobBuilder) {
var bb = new BlobBuilder();
bb.append(data);
out = bb.getBlob(datatype);
console.debug("case 2");
}
else if (e.name == "InvalidStateError") {
// InvalidStateError (tested on FF13 WinXP)
out = new Blob([data], {type: datatype});
console.debug("case 3");
}
else {
// We're screwed, blob constructor unsupported entirely
console.debug("Errore");
}
}
return out;
}
I have no idea how I can solve this ... :-(
regards
Meex

Related

How can I use libusb to send/receive data from ubuntu to Android?

The goal I'm looking to achieve is to send/receive data to/from an Android device from a Linux server. I feel like I've tried all the examples I could find on the Internet as well as reading the libusb APIs, which don't talk at my level of a total noob. Here's what I've got so far:
I've written a program that runs on a Ubuntu server (ARMx64), from examples, I have the following code:
//Error handling removed for brevity
#define BULK_EP_IN 0x08
main(int argc, char* argv) {
libusb_context* libusb_ctxt;
int status;
bool libusb_err = false;
libusb_device** libusb_dvcs = NULL;
bool error = false;
unsigned vid = 0, pid = 0;
unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
struct libusb_device_descriptor desc;
status = libusb_init(&libusb_ctxt);
if (status < 0) {
libusb_err = true;
}
if (libusb_get_device_list(NULL, &libusb_dvcs) < 0) {
error = true;
} else {
libusb_device *dev = NULL;
for (uint16_t idx = 0; (dev = libusb_dvcs[idx]) != NULL; idx++) {
_busnum = libusb_get_bus_number(dev);
_devaddr = libusb_get_device_address(dev);
status = libusb_get_device_descriptor(dev, &desc);
if (status >= 0) {
if (desc.idVendor == vid_arg && desc.idProduct == pid_arg) {
vid = desc.idVendor;
pid = desc.idProduct;
busnum = _busnum;
devaddr = _devaddr;
fnd_dev = dev;
break;
}
}
}
if (fnd_dev == NULL) {
error = true;
} else {
libusb_device_handle* dev_hnd = NULL;
//Connect to device and write data to it.
dev_hnd = libusb_open_device_with_vid_pid(NULL, vid, pid);
if (dev_hnd) {
char str1[64], str2[64];
int e = 0,config2;
char my_string[64];
int length = 0;
int transferred = 0;
e = libusb_get_string_descriptor_ascii(dev_hnd, desc.iManufacturer, (unsigned char*)str1, sizeof(str1));
if (e < 0) {
break;
}
e = libusb_get_string_descriptor_ascii(dev_hnd, desc.iProduct, (unsigned char*)str2, sizeof(str2));
if(e < 0) {
break;
}
e = libusb_get_configuration(dev_hnd, &config2);
if (e == 0) {
if (config2 != 1)
{
libusb_set_configuration(dev_hnd, 1);
if (e!=0) {
libusb_err = true;
}
}
if (!libusb_err) {
if (libusb_kernel_driver_active(dev_hnd, 0) == 1) {
if (libusb_detach_kernel_driver(dev_hnd, 0) == 1) {
libusb_err = true;
}
}
if (!libusb_err) {
e = libusb_claim_interface(dev_hnd, 0);
if (e < 0) {
libusb_err = true;
}
if (!libusb_err) {
active_config(dev, dev_hnd);
memset(my_string, '\0', 64);
strcpy(my_string, "hello sally");
length = strlen(my_string);
e = libusb_bulk_transfer(dev_hnd, BULK_EP_IN | LIBUSB_ENDPOINT_IN, (unsigned char*)my_string, length, &transferred, 0);
if (e == 0 && transferred == length) {
child_log("Write successful!");
child_log("Sent %d bytes with string: %s", transferred, my_string);
}
else {
child_log("Error in write! e = %d and transferred = %d, error desc: %s", e, transferred, libusb_error_name(e));
}
}
}
}
}
e = libusb_release_interface(dev_hnd, 0);
libusb_close(dev_hnd);
}
}
if (libusb_dvcs != NULL) {
libusb_free_device_list(libusb_dvcs, 1);
}
}
if (!libusb_err) {
libusb_exit(libusb_ctxt);
}
}
Everything works, at least doesn't report an error, until I get to the libusb_bulk_transfer call, which it returns a -1, which translates to a LIBUSB_ERROR_IO.
The USB device I'm connecting to is a Samsung Z-Fold3 mobile phone. I'm using the phone as a test OS as I don't have access to the Android tablet that will be used in the final application.
Here's my questions:
How do I know which interface to connect to?
 a) I'll have an application running on the Android device that will be using the same library, hopefully, that will receive the data sent from the Ubuntu server.
How do I know which configuration to use?
Am I doing everything correctly?
Does anyone have any code that can run on the Android to read the data that I'm sending from this code? My goal was to write a program in C that pretty much runs like the one that runs on the Ubuntu server, but reads the data. Once I have that, my next step will be to write data from the Android device to the Ubuntu server using libusb again.
Any help, advice, alternative APIs is very much appreciated.
Thank you!

Why does xamarin android app on real device throws error always but works on simulator

I have a strange problem. I have been developing an app using xamarin forms which is using an API written in php at the back end. iOS version of the app is working fine and android version is working well on simulator . When i archive and install apk file on a real device it always throws error for all the api functions. Could not find the reason, where am going wrong.
Archiving my apk file with armeabi-v7a and linking option as user and Sdk assemblies only in release mode.
Am I missing any properties to be set for archiving my project?
Any help would be appreciated.
public async void OnLogin()
{
string url = "http://www.example.com/UserController/login";
HttpClient client = new HttpClient();
object userjson = new
{
email = Email.Text.ToLower(),
password = Password.Text
};
var myContent = JsonConvert.SerializeObject(userjson);
Console.WriteLine("Post Content" + myContent);
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
Console.WriteLine("Inside Login() Method");
Console.WriteLine("Json Content::" + myContent);
Console.WriteLine("Json Byte::" + byteContent.ReadAsStringAsync());
var response = await client.PostAsync(url, byteContent).ConfigureAwait(false);
var code = response.StatusCode;
Console.WriteLine("Code::" + code);
if (code.ToString() == "OK")
{
string res = response.Content.ReadAsStringAsync().Result;
App.serverToken = "activated";
App.Current.Properties["Token"] = App.serverToken;
await Application.Current.SavePropertiesAsync();
isValid = true;
Console.WriteLine("Token::" + App.serverToken);
}
else
{
isValid = false;
Device.BeginInvokeOnMainThread(() =>
{
LoginFaild.Text = "InCorrect Email or Password";
Email.Text = string.Empty;
Password.Text = string.Empty;
});
}
}
This is the method where am accessing API using Postasync.

Signal R persistent connection on phonegap apps (android and ios)

I am using SignalR persistent connection for smooth communication between my client and server. All the web communications work really fine.
Now I am trying to do the same with my PhoneGap apps. It doesn't work. Is there any reason?
Here is my code
StartEvents = function () {
connection = $.connection(connectionString);
connection.logging = true;
connection.received(function (result) {
for (i = 0; i < result.events.length; ++i) {
}
});
connection.start().done(function () {
console.log("connected");
});
};
It does log out connected at the start when the app is connected the first time. But then as events keep happening nothing is pushed from the server.
Server code is this
public class ApiConnection : PersistentConnection
{
protected override Task OnConnected(IRequest request, string connectionId)
{
StartBroadcast(connectionId);
return base.OnConnected(request, connectionId);
}
}
private void StartBroadcast(string connectionId)
{
var timerCall = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1));
_subscription = timerCall.Subscribe(async res =>
{
List<dynamic> result = pull();
if (result != null && result.Count > 0)
await Connection.Send(connectionId, new
{
id = _newestId,
events = result
});
});
}

Using ZXing in Xamarin for Android, how do I stop continuous scanning right after I get my result?

I'm using ZXing in an Android app being developed in Xamarin to scan a QR code and start playing the corresponding audio file automatically.
My problem is that when I get a result from scanning, it takes some time for the audio player activity to load so it gets called twice or more due to subsequent successful scannings.
Is there a way to stop continuous scanning as soon as I get a correct result?
Here's the code:
//Start scanning
scanner.ScanContinuously(opt, HandleScanResult);
}
private void HandleScanResult(ZXing.Result result)
{
string msg = "";
if (result != null && !string.IsNullOrEmpty(result.Text))
{
msg = result.Text;
var playerActivity = new Intent(myContext, typeof(AudioActivity));
//-------------------------------------------------------------
// Prerequisite: load all tracks onto "Assets/tracks" folder
// You can put here qr code - track assignments here below
// msg: decoded qr code
// playerActivity.Putextra second parameter is a relative path
// under "Assets" directory
//--------------------------------------------------------------
//Iterate through tracks stored in assets and load their titles into an array
System.String[] trackArray = Application.Context.Assets.List("tracks");
bool trackFound = false;
foreach (string track in trackArray)
{
if (track.Equals(msg + ".mp3"))
{
playerActivity.PutExtra("Track", "tracks/" + msg + ".mp3");
for (int i = 0; i < PostList.postList.Count; i++)
{
if (PostList.postList.ElementAt(i).code.Equals(msg))
playerActivity.PutExtra("TrackTitle", PostList.postList.ElementAt(i).title);
}
myContext.StartActivity(playerActivity);
trackFound = true;
}
}
Thank you!
Old question but i'll post it anyway for anyone still looking for this information.
You need your scanner to be a class variable. This is my code:
public MobileBarcodeScanner scanner = new MobileBarcodeScanner();
private void ArrivalsClick(object sender, EventArgs e)
{
try
{
if (Arrivals.IsEnabled)
{
MobileBarcodeScanningOptions optionsCustom = new MobileBarcodeScanningOptions();
scanner.TopText = "Scan Barcode";
optionsCustom.DelayBetweenContinuousScans = 3000;
scanner.ScanContinuously(optionsCustom, ArrivalResult);
}
}
catch (Exception)
{
throw;
}
}
private async void ArrivalResult(ZXing.Result result)
{
if (result != null && result.Text != "")
{
// Making a call to a REST API
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
int? res = JsonConvert.DeserializeObject<int>(resp.Content);
if (res == 0)
{
scanner.Cancel(); // <----- Stops scanner (Something went wrong)
Device.BeginInvokeOnMainThread(async () =>
{
await DisplayAlert("..", "..", "ΟΚ");
});
}
else
{
Plugin.SimpleAudioPlayer.ISimpleAudioPlayer player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
player.Load("beep.wav");
player.Play(); // Scan successful
}
}
else
{
scanner.Cancel();
Device.BeginInvokeOnMainThread(async () =>
{
await DisplayAlert("..", "..", "ΟΚ");
});
}
}
}

dnsjava and Android

I have an Android app to which I am trying to add DNS SRV record detection. I know it is possible, based on the existence of apps such as DNS Lookup, which I have installed, and it works just fine.
I am using dnsjava and this code runs fine as a stand-alone Java application on my machine, but when I run it on my Android device, I just get the "Error!" message:
Lookup lookup = new Lookup(serviceName, Type.SRV, DClass.IN);
Resolver resolver = new SimpleResolver();
lookup.setResolver(resolver);
lookup.setCache(null);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
String responseMessage = null;
String listingType = null;
for (int i=0; i < records.length; i++) {
if (records[i] instanceof SRVRecord) {
listingType = ((SRVRecord) records[i]).toString()
}
}
System.out.println("Found!");
System.out.println("Response Message: "+responseMessage);
System.out.println("Listing type: "+listingType);
} else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
System.out.println("Not found.");
} else {
System.out.println("Error!");
}
Any ideas why this isn't working?
Using a very different setup for SRV lookup in Android; I found they always failed with a 'not found', unless I add the following to my Android Manifest:
<uses-permission android:name="android.permission.INTERNET" />
I am not allowed to comment -- otherwise I would.
Make more else if statements, for example:
else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
System.out.println("Not found.");
} else if (lookup.getResult() == Lookup.TRY_AGAIN) {
System.out.println("Error!1");
} else if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) {
System.out.println("Error!2");
} else if (lookup.getResult() == Lookup.UNRECOVERABLE) {
System.out.println("Error!3");
}
Also, try changing: DClass.IN to DClass.ANY

Categories

Resources