Adobe air... launch website but pick which browser? - apache-flex

OK I know that in Adobe Air you can call navigateToURL(new URLRequest(url)) and it will open the users default web browser to open the page.
Also now in AIR 2 you can launch any application.
So I am wondering if there is a way I can launch a particular browser to open a page in?

I it turns out with AIR 2 you can run command ling arguments so I was able to achieve what I wanted like so:
private function openApp():void
{
if(NativeProcess.isSupported)
{
var file:File = File.userDirectory;
file = file.resolvePath("AppData/Local/Google/Chrome/Application/chrome.exe");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var process:NativeProcess = new NativeProcess();
var args:Vector.<String> = new Vector.<String>();
args.push("https://www.google.com");
nativeProcessStartupInfo.arguments = args;
process.start(nativeProcessStartupInfo);
}
}

If you're using navigateToURL it, basically, passes the URL to the operating system and opens the default application for handling such requests. You can use navigateToURL to open word documents and other files too.
I was pretty sure that the NativeProcess features of AIR 2 allow you to launch applications, but I did not believe they allow you introspect the system to discover what browsers exist and where the DLL / EXE files are.
A good article on the native process stuff: http://www.adobe.com/devnet/air/flex/quickstart/interacting_with_native_process_02.html

Related

Send data from Share Extension to Xamatin.Forms app

I work on Share Extension. And it only has a sample project (following link) and a general extension documentation.
Basic project:
Extension documentation:
When I click share with my app on iphone (for example on photos), I want to send this file to my app and upload it remote server. But I couldn't find anyway to send object from share extension. I looked up and probably I need to use "NSUserDefaults" and I tried to use it that:
I did necessary settings (creating group id, app id etc) on my apple developer account.
I did necessary settings on my project Entitlements.plist
I try to send on ShareViewController - DidSelectPost method in the my project's share extension as below:
var default = new NSUserDefaults ("group.com.myapp.AppName", NSUserDefaultsType.SuiteName);
default.SetString ("Test content", "TestKey");
default.Synchronize ();
4)I try to receive string data on my main project's AppDelegate as below:
var default = new NSUserDefaults ("group.com.myapp.AppName", NSUserDefaultsType.SuiteName);
var key = default.StringForKey ("TestKey");
string value = key;
But I couldn't do it. And I saw someone did this with OpenUrl function. I tried this and this didn't work.
I started mobile programming with Xamarin forms and I don't know enough native iOS programming (I only learn with Xamarin). I think share extension has insufficient documentation.

PhoneGap Local Storage WebSQL, IndexedDB, html5sql, lawnchair

I am trying to figure out the best way to store data in my cross platform app I am developing using PhoneGap.The API instructions suggest using WebSQL however this will no longer be supported, and IndexedDB is currently only for Windows / Blackberry.
There are many different questions on here many of the answers are really old and this, but I cannot seem to find the most popular js library for shipping an app with an existing database? (I.e. a good helper .js to simplify things).
I looked at HTML5SQL but the documentation is very sparse, lawnchair I am not sure about.
I don't know if this question will get flagged for being more preference bound, but I will give my 2 cents if it can help.
I have been able to ship an app with an existing database using SQLite with Phonegap/Cordova. Basically how I did it in Android was using the lite4cordova SQLite plugin:
https://github.com/lite4cordova/Cordova-SQLitePlugin
In the native code on load, I would check the default directory to see if a database with a specific name exists:
try {
File dbFile = getDatabasePath("data.db");
Log.v("info", "dbfiledir: " + dbFile.getAbsolutePath());
if (!dbFile.exists()) {
this.copy("data.db", dbFile.getAbsolutePath());
}
} catch (Exception e) {
e.printStackTrace();
}
And if it does not exist, copy the database file from the assets folder to the default database directory:
void copy(String file, String folder) throws IOException {
File CheckDirectory;
CheckDirectory = new File(folder);
String parentPath = CheckDirectory.getParent();
File filedir = new File(parentPath);
//File file2 = new File(file);
//Log.v("info", "filedir: " + file2.getAbsolutePath());
if (!filedir.exists()) {
if (!filedir.mkdirs()) {
return;
}
}
InputStream in = this.getApplicationContext().getAssets().open(file);
File newfile = new File(folder);
OutputStream out = new FileOutputStream(newfile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.close();
}
Now when the app loads, it will only copy if the database does not already exist. I can open the database using simply (Syntax may vary depending on plugin):
db = window.sqlitePlugin.openDatabase({
name : "data"
});
I will soon be performing the same logic on the iOS side, but I think it should be similarly straightforward.
That being said, there is a plugin listed on http://plugreg.com that provides a helper library for shipping prepopulated databases with WebSQL:
https://github.com/Smile-SA/cordova-plugin-websqldatabase-initializer
I wanted to use SQLite for my project so I opted for the copy on load method. Good luck!
Latest Update:
New Cross Platform Cordova WebSQL plugin by MS Open Tech
Microsoft Open Technologies is publishing the new open source WebSQL plugin for Apache Cordova and PhoneGap. This plugin allows developers to integrate a persistent SQL-based local storage solution in their Cordova apps using the exact same JavaScript code across Android, iOS, Windows Phone and Windows Store.

Flex Image Source Server Side Flash and Air

I'm trying to run my flex application in the air runtime instead of flash runtime. It seems to work perfectly except the images. Adobe Air runtime tries to load them. Is there a way to change the root adresses for Image to server side? If possible I'd like to use the same code for flash runtime and air runtime .. "single codebase ;-)"
var icon:Image = new Image();
icon.source = "images/test.png";
regards
cyrill
Typically I would simply package the assets into the AIR app. That way the relative paths would be valid both in the web app and the desktop app. However, since you pointed out in the comments that we're talking 10000 images you'll have to find another solution.
What you need is a variable that is configurable for each type of project. The final code to access your images should look like:
var icon:Image = new Image();
icon.source = rootUrl + "/images/test.png";
That rootUrl may be "" for the web app, and "http://www.mydomain.com" for the desktop app. Or it could be the absolute path in both cases. It doesn't matter: we don't want to hardcode that URL into our application.
Create a .properties file (or XML, or JSON; whatever configuration file you like) that contains the value for rootUrl and read that into your application model. This configuration file can be packaged into the AIR app.
A .properties file will look like this:
#myapp.properties
rootUrl=http://www.mydomain.com
For reading the file, you could use AIR's file streaming capabilities, but I suggest you load it the old-fashioned way with a URLLoader: this way it'll work both in the web and the desktop app.

Flex standalone application with no database

I am trying to develop an application which can be used locally by my team mates. its a sort of issue tracking application with report generation. am planning to do it on flex. in my company environment, i do have a lots of restrictions like, can't install AIR, no database, etc.
so am planning to develop on flex app, and put it in a shared drive. now the main problem is how can i store data. i have an idea like using excel files as database. I want opinion about this option, as well as, if anyone has tried reading and writing excel files from Flex application I want the suggestions also.
Thanks, Anoop
Flex provides the RemoteObject, WebService, and HTTPService tags for accessing remote data and services. AIR Expands that a bit with some APIs for local file access (File) and SQL Lite database.
Without AIR APIs you won't be able to write local files; and I doubt you can write them. You could try to use HTTPService with a "file://" URL. I would expect cross domain issues.
Can you set up the Flex app to access a remote server? If so, you can have the server deal with creating and editing the excel files. but, if you could do that why not use a real database?
You can look at other tools to create desktop applications from Flex. I believe Janus is one option ( http://www.janus-flash.com/ ). You could also use Flash Pro and publish to an executable; but it would be difficult, but possible, to make that support Flex code. Zinc is another option ( http://www.multidmedia.com/ ).
If AIR isn't allowed, I'm not sure why these other options would be, though. I can't help but wonder if you're better off exploring an MS Access solution instead of trying to turn client/server technologies into desktop technologies.
You can read/write to local files using the FileReference class. I've used the FileReference class for opening and saving images without using serverside code.
Here is an example:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.FileReferenceList;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//load a file when the application starts
var fileRef:FileReference = new FileReference();
var fileRefList:FileReferenceList;
fileRefList = new FileReferenceList();
fileRef.addEventListener(Event.SELECT, function(evt:Event):void {
fileRef.load();
});
fileRef.addEventListener(Event.COMPLETE, function(evt:Event):void
{
//do something with the loaded data here
trace(fileRef.data);
onSave();
});
var arr:Array = [];
arr.push(new FileFilter("Data file", "*.dat"));
//prompt the user for the file to load
fileRef.browse(arr);
}
private function onSave():void
{
var fileRef:FileReference = new FileReference();
fileRef.save("this is my data to save");
}
}
}

Open local file with AIR / Flex

I have written an AIR Application that downloads videos and documents from a server. The videos play inside of the application, but I would like the user to be able to open the documents in their native applications.
I am looking for a way to prompt the user to Open / Save As on a local file stored in the Application Storage Directory. I have tried using the FileReference + URLRequest classes but this throws an exception that it needs a remote url.
My last resort is just copying the file to their desktop : \
You can use the new openWithDefaultApplication(); function that's available on the File class (I believe it's only available in AIR 2)
eg:
var file:File = File.desktopDirectory.resolvePath(fileLocation);
file.openWithDefaultApplication();
Only way I could figure out how to do it without just moving the file and telling the user was to pass it off to the browser.
navigateToURL(new URLRequest(File.applicationStorageDirectory.nativePath + "/courses/" + fileName));
This is the first release of the FluorineFx Aperture framework.
The framework provides native OS integration (Windows only) support for AIR desktop applications.
The framework extends Adobe AIR applications in a non-intrusive way: simply redistribute the provided libraries with your AIR application, at runtime the framework will automatically hook into your application.
Features
Launch native applications and documents with the provided apsystem library
Take screenshots of the whole screen with the provided apimaging library
Access Outlook contacts from an Air application with the provided apoutlook library
http://aperture.fluorinefx.com/
Currently adobe is not supporting opening files in there default applications. Passing it off to the browser seems to be the only way to make it work.
You could however use a FileStream and write a small html file with some javascript that sets the location of an iframe to the file, then after 100ms or so calls window.close(). Then open that file in the browser.
For me it's:
var request:URLRequest = new URLRequest();
request.url = file.url;
navigateToURL(request, "_blank");
The navigateToURL(file.nativePath) didn't work since the path, "/users/mydirectory/..." was outside the application sandbox. AIR only allows some protocols to be opened with navigateToURL().

Resources