web端链接调用 Adobe Air 应用程序

利用自定义URL Protocol来调用应用程序。浏览器在解析到自定义URL Protocol之后,会寻找注册表,然后通过注册表启动相应的程序,然后启动改程序,传入参数。这样就可以在WEB页面调到你的程序了。


一、根据注释部分,把目录和 .exe运行程序 修改成自己的之后,把代码保存到文件,修改后缀名为.reg,双击该文件即可直接导入到注册表中

Windows Registry Editor Version 5.00

/**
	Simu就是在HKEY_CLASSES_ROOT下面添加一个Simu树,
	其中Simu的名称就对应着自定义URL Protocol的名称,在web中调用的时候需要这个名称
*/
[HKEY_CLASSES_ROOT\Simu]


// "x:\\simu\\Simulink.exe"是指定应用程序的路径,注意只能是exe的程序
"URL Protocol"="x:\\simu\\Simulink.exe"

// 协议的名称,可以是任意字符串,后面不会用到
@="SimuProtocol"

// 表示在Simu中再加一个分支,照抄,不用管
[HKEY_CLASSES_ROOT\Simu\DefaultIcon]

// x:\\simu\\Simulink.exe也是对应的程序路径,后面的1照抄
@="x:\\simu\\Simulink.exe,1"


[HKEY_CLASSES_ROOT\Simu\shell]

[HKEY_CLASSES_ROOT\Simu\shell\open]

[HKEY_CLASSES_ROOT\Simu\shell\open\command]

//将路径换成自己的程序路径即可,其中%1表示到参数,参数可以在你的程序simulink.exe中解析得到
@="\"x:\\simu\\Simulink.exe\" \"%1\""

二、在web中调用自定义协议启动程序


需要指出的是:在标题1中的第10行注册表中代码中的%1表示传入参数,就是对应这此处的Simu://hello,解析之后就可以得到参数hello了。

<a href="Simu://hello">SIMU</a>

三、Ari 程序中接收响应


<?xml version="1.0" encoding="utf-8"?>  
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"   
                       xmlns:s="library://ns.adobe.com/flex/spark"   
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">  
    <fx:Declarations>  
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->  
    </fx:Declarations>  
      
    <fx:Script>  
        <![CDATA[  
            import mx.controls.Alert;  
            import mx.events.FlexEvent;  
                      
            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void  
            {  
                NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent);      
                
                 var arguments:Array;   
                 
                  function onInvokeEvent(invocation:InvokeEvent):void   
                  {   
                    arguments = invocation.arguments;   
                    
                    Alert.show(arguments.toString());                  
                  }  
            }  
              
        ]]>  
    </fx:Script>  
</s:WindowedApplication>  


四、也可以直接使用命令行调用

@echo off
start TestBat.exe "你好" "xie"



猜你喜欢

转载自blog.csdn.net/shihongji/article/details/81018487