Is there an as3 API in Air (I'm using 3.2) to access my application version ? The one I give on the App Store or Android Market ?
Yeah you can pull it directly from the application xml descriptor. Something like this should work:
var descriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = descriptor.namespace();
var version:String = descriptor.ns::version[0];
Looks like it's different for Air 4.0
This worked for me:
var descriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = descriptor.namespace();
var version:String = descriptor.ns::versionNumber;
var _descriptor:XML = nativeApplication.applicationDescriptor;
var ns:Namespace = _descriptor.namespace();
var version:String = _descriptor.ns::versionNumber;
This is what works for me. "descriptor" var is used in AIR 3.2 for a UIComponentDescriptor, so I couldn't use that variable name. Also, statically accessing nativeApplication (NativeApplication.nativeApplication) gave me a null pointer reference, so I just grabbed it directly.
Lastly, versionNumber is what stores the version in AIR 3.2.
Related
I have been trying a ( i hope) simple bit of Android hyperloop code directly within a titanium project (using SDK 7.0.1.GA and hyperloop 3).
var sysProp = require('android.os.SystemProperties');
var serialNumber = sysProp.get("sys.serialnumber", "none");
But when the app is run it reports
Requested module not found:android.os.SystemProperties
I think this maybe due to the fact that when compiling the app (using the cli) it reports
hyperloop:generateSources: Skipping Hyperloop wrapper generation, no usage found ...
I have similar code in a jar and if I use this then it does work, so I am wondering why the hyperloop generation is not being triggered, as I assume that is the issue.
Sorry should have explained better.
This is the jar source that I use, the extraction of the serial number was just an example (I need access to other info manufacturer specific data as well), I wanted to see if I could replicate the JAR functionality using just hyperloop rather that including the JAR file. Guess if it's not broke don't fix it, but was curious to see if it could be done.
So with the feedback from #miga and a bit of trial and error, I have come up with a solution that works really well and will do the method reflection that is required. My new Hyperloop function is
function getData(data){
var result = false;
var Class = require("java.lang.Class");
var String = require("java.lang.String");
var c = Class.forName("android.os.SystemProperties");
var get = c.getMethod("get", String.class, String.class);
result = get.invoke(c, data, "Error");
return result;
}
Where data is a string of the system property I want.
I am using it to extract and match a serial number from a Samsung device that is a System Property call "ril.serialnumber" or "sys.serialnumber". Now I can use the above function to do what I was using the JAR file for. Just thought I'd share in case anyone else needed something similar.
It is because android.os.SystemProperties is not class you can import. Check the android documentation at https://developer.android.com/reference/android/os/package-summary.html
You could use
var build = require('android.os.Build');
console.log(build.SERIAL);
to access the serial number.
My App and Sqlite connection works on simulator but does not work when publishes on android device.
Below are the sample codes, I have tried, all work on simulator but not on android phone
// SAMPLE-1
var conn:SQLConnection = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openSuccess);
conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
var fileLocation:File = File.applicationStorageDirectory.resolvePath("assets/weddingsql.sqlite"); ;
conn.openAsync(fileLocation, SQLMode.READ);
// SAMPLE-2
var fileLocation:File = File.applicationStorageDirectory.resolvePath("assets/weddingsql.sqlite"); ;
var storageDbFilePath:File = File.applicationStorageDirectory.resolvePath("weddingsql.sqlite");
fileLocation.copyToAsync(storageDbFilePath, true);
fileLocation.addEventListener(Event.COMPLETE, fileCopiedHandler);
function fileCopiedHandler(event:Event):void {
trace("File Copied....");
conn.openAsync(storageDbFilePath, SQLMode.READ);
}
// Used in both the samples
private function openSuccess(evt:SQLEvent):void{
trace(" can not make connection to Database "); }
private function openFailure(evt:SQLErrorEvent):void{
trace(" can not make connection to Database ");}
And lastly, I suggest all as3 air developer to move on to native android if possible.
to use sqlite in android try add in manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
FileReference actions work properly in my workspace but wont when installed in mobile/android phone.
Publish Settings:
Target - Air 3.2 for Android
Script - AS 3.0
Air for Android Settings:
Checked the following
WRITE_EXTERNAL_STORAGE
Here's what's happening, I have 3 buttons calling the FileReference.
One is the for browsing(.browse()) what to load(.load()). Here when I clicked the button for browse, it will prompt "No files selected" even I haven't selected yet. The browse dialog wont even show.
In saving(.save()), it won't show the save dialog box.
Any idea whats happening? all of those are working fine in Flash Pro before publishing
From the AS3 documentation:
Note: In Adobe AIR, the File class, which extends the FileReference class, provides more capabilities and has less security restrictions than the FileReference class.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html
Try something like:
import flash.filesystem.*;
var _file:File = File.applicationStorageDirectory.resolvePath("yourfile.xml");
var _readFileStream:FileStream = new FileStream();
_readFileStream.open(Main._file, FileMode.READ);
var _loadedData:String = String(_readFileStream.readUTFBytes(_readFileStream.bytesAvailable));
_readFileStream.close();
trace(_loadedData);
and to save
var _file:File = File.applicationStorageDirectory.resolvePath("yourfile.xml");
var _writeFileStream:FileStream = new FileStream();
_writeFileStream.open(Main._file, FileMode.WRITE);
_writeFileStream.writeUTFBytes(_loadedData);
_writeFileStream.close();
I have developed android phonegap application using phonegap 1.9.0.Its was working fine in android 2.2 and 4.0.Later i changed the phonegap version and currently i am using phonegap 2.1.0.Its working fine in android 2.2 but in android 4.0 i cannot able to navigate from one page to another,while passing the value as query string.
Here is my code:
function onClick()
{
var id="2";
window.open("index2.html?id="+id);
}
Index2.html:
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
return pair[1];
}
}
}
Get the value in index2.html as
var id=getQueryVariable("id");
Please help me.Thanks in Advance.
I switched to 2.0.0 specifically due to a bug with query string in prev versions and android 4. Gave the 2.1.0 a try and it is broken again. Why I wanted to upgrade? Because 2.0.0 has camera issues like user takes a pic that is supposed to show on a web page and the success function or fail are not fired. Tried with 10, 50 and 100 % picture quality. It works on my phone but not on others with same ver Android.
Is there a way to open one app from another app in Air? Example: I open app A which contains a button that opens app B when clicked. Suppose both A and B are separated apps that are installed in the device and that this device could be a PlayBook, an Ipad or an Android tablet.
Thanks.
You'd have to go the Air Native Extension(ANE) route. Either create one ANE solution for iOS and Android each, or one ANE that abtracts the functionality into one solution. How to launch app A from app B on Android is not the same as on iOS. See this answer in SO.
To implement it on Android, you'd wraps the native Android Java solution in a ANE. The native Java code uses the package name of app B to launch app B from app A:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.yourdoman.yourapp");
startActivity(intent);
Here is a video tutorial on how to launch an Activity through an ANE which you can build on to create your ANE. You'd have to tailor the solution to launch by domain instead of Activity.
Since I really don't know the specifics of what you are trying to do, I think I should point you here: http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications/ It is the best answer to the question that I am aware of.
private function getHostName() : void
{
if (NativeProcess.isSupported)
{
var OS : String = Capabilities.os.toLocaleLowerCase();
var file : File;
if (OS.indexOf('win') > -1)
{
// Executable in windows
file = new File('C:\\Windows\\System32\\hostname.exe');
}
else if (OS.indexOf('mac') > -1 )
{
// Executable in mac
}
else if (OS.indexOf('linux'))
{
// Executable in linux
}
var nativeProcessStartupInfo : NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var process : NativeProcess = new NativeProcess();
process.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutput);
process.start(nativeProcessStartupInfo);
process.closeInput();
}
}
private function onOutput(event : ProgressEvent) : void
{
var strHelper : StringHelper = new StringHelper();
formStationID.text = event.target.standardOutput.readUTFBytes(event.target.standardOutput.bytesAvailable);
formStationID.text = strHelper.trimBack(formStationID.text, "\n");
formStationID.text = strHelper.trimBack(formStationID.text, "\r");
}
This code gets the workstation name. I have heard this can be done on IOS and Android, but I haven't found any proof of that yet.