Idea for a Cool AIR Application

Posted in Flash by theFlashBlog on the 08-23-2010

I often get ideas for things to build but don’t have the time to actually see them through. Recently I came across an API for accessing the Android Marketplace that was written in Java. Google has no official API for this as you are supposed to only be able to access it from your device. The idea was to build an AIR application that would allow you to search and browse on the market. There are many websites out there that do it but they are messy and riddled with ads. This would be clean, fast, and could include advanced features like directly connecting to your device.

I started by trying to port it directly to AS3. This was going great until I had to set a cookie header with the authentication details when querying the market. This is not allowed in ActionScript and I could find no workaround. A proxy on my web server could work but this is for an AIR application. Next I decided to simply call to the JAR file using the AIR 2.0 NativeProcess API. This worked great and I was able to get results returned. The issue then was that it seemed to be badly formed JSON. The JSON library in as3corelib kept giving me errors so that is where I left it.

If someone out there is looking for an idea for something to build, I think this would be a great app that would garner some attention. Make sure you send me the URL when you’re done. Below is the code I was using to interact with the JAR file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private var np:NativeProcess;
private var npi:NativeProcessStartupInfo;

protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
    np = new NativeProcess();
    npi = new NativeProcessStartupInfo();
    npi.executable = File.applicationDirectory.resolvePath("C:/Windows/System32/java.exe");
    var args:Vector.<String> = new Vector.<String>();
    args.push("-jar");
    args.push(File.applicationDirectory.resolvePath("androidmarketapi.jar").nativePath);
    args.push("YOUR_GMAIL_ADDRESS_HERE");
    args.push("YOUR_PASSWORD_HERE");
    args.push("SEARCH_TERM");
    npi.arguments = args;
    np.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onData);
    np.start(npi);
}

private function onData(e:ProgressEvent):void
{
    var str:String = np.standardOutput.readUTFBytes(np.standardOutput.bytesAvailable);
   
    if(str.indexOf("app") != -1)
    {
        str = str.substr(str.indexOf("app"));
        var obj:Object = JSON.decode(str, false); //FAIL
    }
}
Read full article

  1. Responses to “Idea for a Cool AIR Application”

Post a Comment

captcha