IBM Worklight 6.0 - Cordova camera simulation in the Mobile Browser Simulator doesn't work - ibm-mobilefirst

My camera code was working fine in WL 5.0.6 and the mobile browser simulator would correctly display the image. Now I moved to WL 6.0 andI get the following error when using the preview in the Mobile Browser Simulator and using the Cordova camera simulation to get a fake picture.
I am using Chrome for the preview.
Not allowed to load local resource: file:///C:/Users/Administrator/cordova/internal/sim/camera/camera1_m.jpg wljq.js:2374
The code is similar to this
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
Note that if I use the DATA_URL, it seems OK with the mobile browser simulator. Just the FILE_URI doesn't seem to be working with the mobile browser simulator.

The Worklight 6.0 Mobile Browser Simulator supports Cordova 2.6 APIs. For navigator.camera.getPicture the following destination types can be used in WL 6.0:
Camera.DestinationType = {
DATA_URL : 0, // Return image as base64 encoded string
FILE_URI : 1, // Return image file URI
NATIVE_URI : 2 // Return image native URI (eg. assets-library:// on iOS or content:// on Android)
};
Example:
navigator.camera.getPicture(
function(data) {
document.getElementById('camera_status').innerHTML = "Success: picture located at " + data;
var img = document.getElementById('camera_image');
img.style.display = "none";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
},
{ quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM, encodingType: fileType});
Try clearing your browser cache and then be sure to accept the applet permission dialogue on Mobile Browser Simulator startup. Also make sure that your file permissions will allow transfer from the C:/Users//cordova/internal/sim/camera/ folder as that is where the applet stores the camera sim image content.
Cordova 2.6 Camera API reference:
http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html

Funny, that there is already a troubleshooting document for your problem.
http://www-01.ibm.com/support/docview.wss?uid=swg21614861
It looks like DATA_URL didnt work in WLv5, while (if you are right) FILE_URI is not working since WLv6.

Related

Embedding Wistia video in a Mobile App developed using Titanium

We are developing a Mobile App using the Titanium framework, we need to embed some videos in one of the screens. Appcelerator API documentation that I am following is located here. My code looks as follows, currently it shows a blank screen :
var welcomeWin = Ti.UI.createWindow({
title:'Welcome Video',
backgroundColor:'#fff'
});
var videoplayer = Titanium.Media.createVideoPlayer({
top:2,
autoplay:true,
height:300,
width:300,
url:'https://fast.wistia.net/embed/iframe/thewistiaurl',
mediaControlStyle:Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT
});
welcomeWin.add(videoplayer);

titanium ti.paint toimage() is returning {} after drawing on ios

the following code is resulting in to different outputs different android and ios. myBlob below is {} on ios - the image is empty even after drawing on the screen. in Android it an object with properties and is working fine, but iOS the image is always blank.
This was working before in past ios versions and builds so am I not building it right? We are using 5.3.0 GA for titanium SDK. I have the module checked for iOS in the TiApp Editor.
function uploadImage(signed) {
if (signed) {
var myBlob;
try {
myBlob = $.viewPaint.toImage();
var myImage = Titanium.Utils.base64encode(myBlob).toString();
$.nextAction.image = myImage;
} catch (ex) {
Titanium.API.error('FAILURE HANDLING SIGNATURE DOCUMENT: ' + ex);
return;
}
}
$.nextAction.perform(Alloy.Globals.requests);
}
Ti Paint Module for iPhone
#
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.4.0
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Provides a paint surface user interface view.
author: Jeff Haynie
license: Appcelerator Commercial License
copyright: Copyright (c) 2010-2014 by Appcelerator, Inc.
# these should not be edited
name: paint
moduleid: ti.paint
guid: 43f13063-d426-4e9c-8a7a-72dc5e4aec57
platform: iphone
minsdk: 3.4.1.GA
prior code that adds execute to action object
var route = action.action.uri;
Ti.API.info('route = ' + route);
newAction.execute = function(requestManager) {
Titanium.App.fireEvent('app:index:view:requested',
controller : 'signscreen',
uri : route
});
};
code that fires the event to open:
Titanium.App.fireEvent('app:index:view:requested', {
controller : 'signature'
});
if you have anything in your view hierarchy that overlays your paintview such as a confirmation dialog or closing the view in a navigation controller and not grabbing your paintview prior to the window closing the paintview will always return empty. android will continue to work fine but ios will not as the view is not present in the view hierarchy.
Your console log value of {} is a red herring.
Tested on:
TiSDK 5.2.2.GA, 5.3.0.GA
ti.paint: 1.4.0, 1.4.1 (our version with fixes that have been ignored by appc)
With <run-on-main-thread>false</run-on-main-thread> in tiapp.xml
Using the example app.js from the module and adding the following:
var buttonSave = Ti.UI.createButton({ bottom:100, right:10, width:75, height:30, title:'Save' });
buttonSave.addEventListener('click', function(e){
var test = paintView.toImage();
console.log(test.length);
console.log(paintView.toImage());
var imageFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,"testing.png");
imageFile.write(paintView.toImage());
});
win.add(buttonSave)
You will find that
The logged value always will be {}
The length of the object you assigned toImage() to increases as you add pixels to your paintView
The image DOES get written to a file.

window.open addEventListener does not work on "Mobile Browser Simulator"

I'm using IBM Worklight 6.2
I'm using window.open to load some external pages for OAuth and I configure event listeners for the opened window.
var authWindow = window.open(authUrl, '_blank', 'location=yes');
authWindow.addEventListener('loaderror', function(e) {
console.log(">> load error. event: " + JSON.stringify(e));
});
also for "load" and "loadstart" events.
This works in Android and iOS but when I preview the app in the "Mobile Browser Simulator" the eventListeners are not executed.
I have also tested creating a "desktopbrowser" application.
Any idea?
Loaderror, loadstart, and loadstop are specific to Cordova and not supported in the Mobile Browser Simulator. It would be best to test these on emulator or device. Please see: http://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#addEventListener

How to open url in default browser using titanium in Blackberry

I am currently working on a project in titanium .I wish to open url in default browser of BB10
simulator instead of webview used in the app on click event .I am using the following code
var win =Ti.UI.createWindow({
title:'Test'
});
var webview=Ti.UI.createWebView({
url:"http://demo.php.otssolutions.com/videoapp-uat/home"
});
win.add(webview);
webview.addEventListener('click',function(e){
var url=e.url;
Ti.API.info(url);
Titanium.Platform.openURL("http://demo.php.otssolutions.com/videoapp-uat/home");
});
win.open();
Thanks in advance for any help

How to offer files for download?

I have a problem. In my sencha touch application I have list items like .pdf, .png, ... If user taps on one of them file should be download on his mobile device.
How can I do this? I have no idea :-)
Thanks for help.
You can use phonegap file api to download files, If you are using sencha touch 2.3 or above just follow the bellow steps.
Install phonegap in sencha project by executing following command at the project root and this command creates phonegap folder inside project root.
sencha phonegap init
You need to install two phonegap plugins to work with file api by executing two following commands inside phonegap folder.
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
Now you can start working file api in sencha touch and you can follow below code i used for one of my project.
If you want to download file, first you need to read device file system and then using file system you can download files.
getFileSystem : function(){
var me =this;
Ext.Viewport.mask({
xtype: 'loadmask',
message: 'Downloading files..'
});
var extfs = Ext.create("Ext.device.filesystem.Cordova");
extfs.requestFileSystem({
type: window.PERSISTENT,
size: 1024 * 1024,
success: function(fSys) {
window.fileSys = fSys;
Ext.Viewport.unmask();
me.fileDownload("myfolder/filename.png","http://someurl");
},
failure: function(error){
alert(error);
Ext.Viewport.unmask();
}
});
}
I am passing fileLocation(location you want to store file inside phone) & url in above function.
fileDownload: function(fileLocation,Url){
Ext.Viewport.mask({
xtype: 'loadmask',
message: 'Downloading files..'
});
var me = this;
var fSys = window.fileSys
if(fSys){
var file = Ext.create('Ext.device.filesystem.FileEntry',
fSys.fs.root.toURL() + fileLocation, fSys);
file.download({
source: Url,
success: function(entry){
Ext.Msg.alert('SUCCESS', 'Image successfully downloaded');
Ext.Viewport.unmask();
},
failure: function(error){
Ext.Msg.alert('ERROR', 'Download failed');
Ext.Viewport.unmask();
}
});
}
}
Now can see image at internalMemorycard/myfolder/filename.png
Sencha docs
Ext.device.filesystem.Cordova
Ext.device.filesystem.FileEntry
If you are using sencha touch 2.2 or below only change is instead of using sencha class you need to directly use phonegap api.
For reading file system & File download follow phonegap documentation.
Sencha basically operates over HTML, CSS & JS. Rather than doing this using Sencha just implement it similar to how you would do it in HTML then integrate into your application.
Eg: Homework
Try this
document.location= url;
Try the following code it may help you.
var newWindow = window.open('filepath', '_self'); //were filepath is the path of file with extension.