Displaying contact image in HTML using PhoneGap - android

I am trying to display the image with URL content://com.android.contacts/contacts/1/photo in the image element of HTML page.
Although it's a old problem, Can anyone please provide me a complete example to display a contact image in img element using PhoneGap.
Thanks in advance,
prodeveloper.

I read a lot on this probleme and the problem seems to be solved on the cordova 3.2.0
here is my code.
You do not need to create a tempory image or something else.
var init = function () {
var options = new ContactFindOptions();
options.filter = ""; // empty search string returns all contacts
options.multiple = true; // return multiple results
var filter = ["displayName",
"phoneNumbers",
"photos"];
navigator.contacts.find(filter, onSuccess, onError, options);
};
function onSuccess(contacts) {
var contactPhoto;
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].displayName && contacts[i].phoneNumbers) {
contactPhoto = defaultvalue;
if (contacts[i].photos) {
for (var j = 0; j < contacts[i].photos.length; j++)
if (contacts[i].photos[j].value) {
contactPhoto = contacts[i].photos[j].value;
break;
}
}
showContactsModel.Contacts.add(
{
displayName: contacts[i].displayName,
phoneNumbers:contacts[i].phoneNumbers,
photo: contactPhoto
});
}
}
}
and my binding
<img data-bind="attr:{src: photo}" alt="something.png" />

you can directly use
<img src="content://com.android.contacts/contacts/1502/photo" alt="Oops!!">
once you have the url of image !

Related

How to integrate OpenCV with Ionic 3?

I am building a mobile app for body measurement through photo I capture. how I can use OpenCV for the same? How to integrate OpenCV with Ionic framework? Kindly help.
Essentially you can pull in a flavor of the opencv.js framework. The way I've done it is by pulling down some reference like https://docs.opencv.org/3.4.1/opencv.js, and then hosting it somewhere (in case opencv moves it on you). Then include that script in the Ionic project. Be careful how you do that though. It is a big file, so it could take the app longer to load. Some options I've used:
Local Asset
Store the js file in the local assets, and include it in the index.js. If the Ionic app is deployed as a native app, then this asset is already in the app and fairly fast to load.
<script src="assets/js/opencv.js" async></script>
Dynamically load the file (example below)
async ionViewDidLoad() {
let loadingScreen = this.loadingCtrl.create({ content: "Loading Scripts. Please Wait..." });
//Show loading screen & load scripts
try {
await loadingScreen.present();
await this.loadScript();
}
catch (error) {
this.errorMessage = "We had some trouble loading scripts...";
}
finally {
loadingScreen && loadingScreen.dismiss();
}
}
public loadScript(): Promise<any> {
return new Promise((resolve, reject) => {
var isFound = false;
var scripts = document.getElementsByTagName("script")
for (var i = 0; i < scripts.length; ++i) {
if (scripts[i].getAttribute('src') != null &&
scripts[i].getAttribute('src').includes("opencv")) {
isFound = true;
return resolve();
}
}
if (!isFound) {
var dynamicScripts = ["https://docs.opencv.org/3.4.1/opencv.js"];
for (var i = 0; i < dynamicScripts.length; i++) {
let scriptNode = document.createElement('script');
scriptNode.src = dynamicScripts[i];
scriptNode.type = 'text/javascript';
scriptNode.async = false;
scriptNode.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(scriptNode);
scriptNode.onload = resolve;
}
}
});
}

AnalyserNode and AudioContext.createMediaElementSource does not work in mobile

I cannot make work AnalayserNode with AudioContext.createMediaElementSource in mobile devices. It does not work in Safari on iOS and does not work in Chrome on Android. When I do analayser.getByteFrequencyData(buffer); I always get an array with zeros. Is this a bug? where should I report it? Any workaround?
Full code below or in Codepen: http://codepen.io/elranu/pen/WQOerB
var initialized = false;
var audio = new Audio();
audio.src = "http://blogtalk.vo.llnwd.net/o23/show/6/884/show_6884921_2014_09_08_16_11_36.mp3";
audio.crossOrigin = "anonymous";
audio.preload = false;
function init(){
var context = new AudioContext();
var source = context.createMediaElementSource(audio);
var anal = context.createAnalyser();
anal.fftSize = 1024;
var buffer = new Uint8Array(anal.frequencyBinCount);
var lines = [];
var eq = document.getElementById('eq');
for(var index = 0; index < buffer.length; index++){
var line = document.createElement('div');
line.className = 'line';
lines.push(line);
eq.appendChild(line);
}
source.connect(anal);
anal.connect(context.destination);
setInterval(function(){
anal.getByteFrequencyData(buffer);
for(var index = 0; index < buffer.length; index++){
lines[index].style.height = buffer[index] + 'px';
}
}, 50);
}
function startAudio(){
if(!initialized){
init();
initialized = true;
}
audio.play();
}
function stopAudio(){
audio.pause();
}
.line {
width: 2px;
background-color: blue;
margin-left:3px;
display:inline-block;
}
#eq {
height: 500px;
}
<button onclick="startAudio()">Start Audio</button>
<button onclick="stopAudio()">Stop Audio</button>
<div id="eq">
</div>
Update: I have noticed that the AnalayserNode works on mobile if the source of the AudioContext is createBufferSource(). But this is not a viable way to solve the problem. Because to create a buffer I have to do the following request:
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.onload = function(){//stufff...};
And if I do this request, the mobile device will download the full audio, just render the frequency of the audio. With big audios this is no viable solution in mobile, because the user could wait a lot just to start playing.
An example to test this: http://webaudioapi.com/samples/visualizer/
I found the answer, unfortunately is a bug. More information here:
https://code.google.com/p/chromium/issues/detail?id=419446

Accessing the DOM from a Firefox for Android add-on

I am attempting(and failing) to insert elements into every page visited. I am only able to insert elements into the initial page(the page displayed after the add-on has been installed). The code snippet below demonstrates this behaviour.
I have tried placing the logic that inserts the H1 element within onOpenWindow(), although that doesn't seem to make any difference.
NOTE: The code below is in addition to template boilerplate code
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import('resource://gre/modules/Services.jsm');
function loadIntoWindow(window) {
if (!window)
return;
window.NativeWindow.toast.show("Inserting script", "short");
var contentWindow = window.BrowserApp.selectedBrowser.contentWindow;
var document = contentWindow.document;
document.body.innerHTML = "<h1>THIS TEXT WAS INSERTED</h1>";
}
var DOMWindows = Services.wm.getEnumerator('navigator:browser');
while (DOMWindows.hasMoreElements()) {
var aDOMWindow = DOMWindows.getNext();
var allTabs = aDOMWindow.BrowserApp._tabs;
for (var i=0; i<allTabs.length; i++) {
var aContentWindow = allTabs[i].window;
}
}

Loading External Picture in air for android

I need load images from a folder in application directory created in sd Card of mobile android
This is working in PC, but not in mobile version
Some solution ?
var imagesFin:File = File.applicationStorageDirectory.resolvePath("appImages/");
var files:Array = imagesFin.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++){
var picLoader = new Loader();
picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadPicture);
picLoader.load(new URLRequest(files[i].nativePath));
}
function loadPicture(event:Event):void {
var imgAtual = event.target.content;
ContainerImagesList.addChild(imgAtual);
}
This work for me:
var bytes:ByteArray = new ByteArray();
var myFileStream:FileStream = new FileStream();
var myFile:File = File.documentsDirectory.resolvePath(YOUR_PATH);
myFileStream.addEventListener(Event.COMPLETE, fileCompleteHandler)
myFileStream.openAsync(myFile, FileMode.READ);
function fileCompleteHandler(event:Event):void
{
myFileStream.readBytes(bytes);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.loadBytes(bytes);
function imageLoaded(e:Event):void
{
addChild(Bitmap(loader.content));
myFileStream.removeEventListener(Event.COMPLETE, fileCompleteHandler);
myFileStream.close();
}
}
Cheers!
In iOS I never use resolvePath. I just use a relative url like "images/photo.jpg" and it works perfectly on any iOS device.
Instead of resolvePath you could also use URL schemes. It's a lot simpler "app:/images/photo.jpg" or "app-storage:/settings/prefs.xml".
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html
This is what I do to get all images in my image file cache
var imageFolder:File = new File("app:/img");
var getfiles:Array = imageFolder.getDirectoryListing();

Pull to refresh in Titanium for Android

How to pull to refresh?
In Titanium appcelerator I need to show a list of content in tableview. If I pull the view it needs to update. In iPhone I complete but in Android it won't work. Please any one help to solve this problem in Android.
My Android code:-
tableView.addEventListener('scroll',function(e)
{
var offset = e.contentOffset.y;
if (offset < -65.0 && !pulling && !reloading)
{
var t = Ti.UI.create2DMatrix();
t = t.rotate(-180);
pulling = true;
arrow.animate({transform:t,duration:180});
statusLabel.text = "Release to refresh...";
}
else if((offset > -65.0 && offset < 0 ) && pulling && !reloading)
{
pulling = false;
var t = Ti.UI.create2DMatrix();
arrow.animate({transform:t,duration:180});
statusLabel.text = "Pull down to refresh...";
}
});
tableView.addEventListener('dragEnd', function(e)
{
if(pulling && !reloading)
{
reloading = true;
pulling = false;
arrow.hide();
actInd.show();
statusLabel.text = "Reloading...";
tableView.setContentInsets({top:60},{animated:true});
tableView.scrollToTop(-60,true);
arrow.transform=Ti.UI.create2DMatrix();
beginReloading();
}
});
Titanium now supports pull to refresh for BOTH Android (> v6.2.0) and iOS (>3.2.0) with a Titanium.UI.TableView, Titanium.UI.ListView or Titanium.UI.ScrollView object.
See the docs:
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ListView
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.RefreshControl
Sample code taken from the docs:
var win = Ti.UI.createWindow({
fullscreen:true
});
var counter = 0;
function genData() {
var data = [];
for (var i=1; i<=3; i++) {
data.push({properties:{title:'ROW '+(counter+i)}})
}
counter += 3;
return data;
}
var section = Ti.UI.createListSection();
section.setItems(genData());
var control = Ti.UI.createRefreshControl({
tintColor:'red'
})
var listView = Ti.UI.createListView({
sections:[section],
refreshControl:control
});
control.addEventListener('refreshstart',function(e){
Ti.API.info('refreshstart');
setTimeout(function(){
Ti.API.debug('Timeout');
section.appendItems(genData());
control.endRefreshing();
}, 2000);
})
win.add(listView);
win.open();
Is this just the IOS code form the Kitchen Sink example?
There are a couple of attempts at getting this working on Android, though I haven't confirmed that any of them work as expected. From what I understand, the problem is that you can't get the offset the same way in Android as in IOS.
A quick Google search turned up this link, which was referenced from the official Appcelerator forums.
https://gist.github.com/903895

Categories

Resources