Launch camera from HTML 5 app running on Windows 8? - html

I've seen examples using XAML and writing some code in C# - is it possible just using Javascript?

Yes. Here is a blog showing how to: http://blogs.msdn.com/b/davrous/archive/2012/09/05/tutorial-series-using-winjs-amp-winrt-to-build-a-fun-html5-camera-application.aspx

You can write following method for launch camera
function capturePhoto() {
var capture = new Windows.Media.Capture.CameraCaptureUI();
capture.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo)
.then(function (file) {
if (file) {
return file.openAsync(Windows.Storage.FileAccessMode.readWrite);
}
});

Related

Markups Core enterEditMode() returning false

function newMarkupGUI(viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options);
thisViewerId = options.id;
this.viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then(() => {
let extension = this.viewer.getExtension("Autodesk.Viewing.MarkupsCore");
extension.enterEditMode();
console.log(extension.enterEditMode());
});
}
When I am inside my main js file where I initialize the viewer, I am able to access functions such as enterEditMode() like so:
var extension = viewer.getExtension("Autodesk.Viewing.MarkupsCore");
extension.enterEditMode();
This works. But inside my extension called newMarkupsGUI, it seems getExtension() does not work. I am confused about how this all works, as the documentation is pretty sparse. I would rather keep my extension separate and not hard code the functionality of markups where I am initializing the viewer. Any help would be appreciated, thank you.
I think your problem is related to the viewer reference. You don't need to use this.viewer if you have your viewer as function parameter.
When using viewer.loadExtension().then() the loaded extension is returned in the promise.
You can do something like that :
viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then((markupExtension) =>
{
markupExtension.enterEditMode();
});

Download file from drive using appscript

I have a file in Google Drive with id=0B3fqdol6s0bWZHV3RWpoV1gyWkk
And I created appscript to download it over a link automatically. The code looks like this
function doGet(e) {
return HtmlService.createHtmlOutput(downloader());
}
function downloader() {
var out = "<body onload='dllink.click()'>";
out +="<a id='dllink' href='https://drive.google.com/uc?export=download&id=0B3fqdol6s0bWZHV3RWpoV1gyWkk'>wait will download automatically<a/>";
out +="</body>";
return out;
};
Then, I developed it as webapps so my friend can download it easily using link
https://script.google.com/macros/s/AKfycbzzToo8gwgdj30FBLrjA1izcfv4rddjW6VClaEGuNXAqZAkIH7S/exec
It's working perfect on PC browser, but sadly, It can't work on mobile phone browser which doesn't support handle onload event or javascript.
So, is there any solution to make an appscript download a file based on its id automatically?
Try it by using an iFrame:
function doGet(e) {
return HtmlService.createHtmlOutput(downloader());
}
function downloader() {
var out = "<iframe width=\"1\" height=\"1\" frameborder=\"0\" src=\"https://drive.google.com/uc?export=download&id=0B3fqdol6s0bWZHV3RWpoV1gyWkk\"></iframe>";
return out;
};
*Backslashes are for escaping

new APIs for windows phone 8.1

I am trying to use these two methods (of WP 8) in windows phone 8.1, but it gives error and doesn't compile, most probably becasue they are removed. I tried searching the new APIs but couldn't get any. What are other alternatives for these.
Dispatcher.BeginInvoke( () => {}); msdn link
System.Threading.Thread.Sleep(); msdn link
They still exists for Windows Phone 8.1 SIlverlight Apps, but not for Windows Phone Store Apps. The replacements for Windows Store Apps is:
Sleep (see Thread.Sleep replacement in .NET for Windows Store):
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(30));
Dispatcher (see How the Deployment.Current.Dispatcher.BeginInvoke work in windows store app?):
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { });
Dispatcher.BeginInvoke( () => {}); is replaced by
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {});
and System.Threading.Thread.Sleep(); is replaced by
await Task.Delay(TimeSpan.FromSeconds(doubleValue));
Be aware that not only has the API changed (adopting the API from WindowsStore apps), but the way that the Dispatcher was obtained in windowsPhone 8.0 has changed as well.
#Johan Faulk's suggestion, although will work, may return null under a multitude of conditions.
Old code to grab the dispatcher:
var dispatcher = Deployment.Current.Dispatcher;
or
Deployment.Current.Dispatcher.BeginInvoke(()=>{
// any code to modify UI or UI bound elements goes here
});
New in Windows 8.1 Deployment is not an available object or namespace.
In order to make sure the Main UI Thread dispatcher is obtained, use the following:
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
or
CoreApplication.MainWindow.CoreWindow.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
()=>{
// UI code goes here
});
Additionally, although the method SAYS it will be executed Async the keyword await can not be used in the method invoked by RunAsync. (in the above example the method is anonymous).
In order to execute an awaitable method inside anonymous method above, decorate the anonymous method inside RunAsync() with the async keyword.
CoreApplication.MainWindow.CoreWindow.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
**async**()=>{
// UI code goes here
var response = **await** LongRunningMethodAsync();
});
For Dispatcher, try this. MSDN
private async Task MyMethod()
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { });
}
For Thread.Sleep() try await Task.Delay(1000). MSDN

jQuery "load" on webview

I'm trying to use the jQuery .load() function on a <webview/> into a Chrome Packaged App.
This is my test did with an iFrame:
$('<iframe />').attr("src", "http://example.org").load(function(){
$(this).addClass("shown");
}).appendTo('#body');
Fiddle: http://jsfiddle.net/m9ws5/1/
The problem is that when I try to use this code in my packaged app replacing <iframe/> with <webview/> it doesn't fire the load event.
I think the problem is that webview are different from iframe, how can I do?
I've found a solution using the Chrome methods:
onload = function() {
var webview = $("#webview");
webview.on("loadstop", function () {
webview.addClass("shown");
});
}
(always read documentation! https://developer.chrome.com/apps/tags/webview#methods)

What is the best way to OAuth twitter without use of a proxy server or server-side script in a Flash As3 Web Application?

I can't use a proxy server. Can't use google app engine etc.
I can't use server side code. No php or python.
I need to be able to do logins to twitter and post status updates to twitter through an Actionscript 3 web application.
The biggest thing is obviously getting around twitter's crossdomain. Is there a clean ajax version of this or something?
Thanks for the help!
I have had some luck using jQuery to load a feed into flash using:
JS
var flashObj;
$(document).ready(function() {
if (navigator.appName.indexOf("Microsoft") != -1) {
flashObj = window["adidasFlash"];
} else {
flashObj = document["adidasFlash"];
}
});
function loadTwitterFeed(screenName) {
$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name="+screenName+"&callback=?", function(data) {
console.log(data);
flashObj.tweetLoadComplete(data);
});
}
AS
ExternalInterface.addCallback("tweetLoadComplete", tweetLoadComplete);
loadFeed("BarackObama");
function loadFeed(screenName:String):void {
ExternalInterface.call("loadTwitterFeed", screenName);
}
function tweetLoadComplete(obj:Object):void {
for each (var o:Object in obj) {
trace(o.text);
}
}
Hope that helps.