AIR程序的多开

AIR应用通常不能像QQ那样能进行多开操作。

 

为了让一个用AIR做的客户端能实现多任务,我找到得办法是运行程序时自动修改配置文件的id标签内的内容。

 

然后再关闭程序时又必须还原成原有的id,因为只有id一致才能实现更新功能。

 

 

主程序:multiapp.mxml

 

<?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:Script>
		<![CDATA[
			import flash.filesystem.File;
			import flash.filesystem.FileMode;
			import flash.filesystem.FileStream;
			
			import mx.events.FlexEvent;
			import mx.formatters.DateFormatter;
			
			private var oldid:String;
			private var reg:RegExp = /<id>.*<\/id>/;
			
			protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
			{
				var df:DateFormatter = new DateFormatter();
				df.formatString = "YYYYMMDDHHNNSS";
				var time:String = df.format(new Date());
				var newid:String = "<id>com.roy"+time+"</id>";
				
				var f:File =new File(File.applicationDirectory.resolvePath(
					"META-INF/AIR/application.xml").nativePath);
				var fs:FileStream = new FileStream();  
				fs.open(f,FileMode.READ);      
				var str:String = new String(fs.readUTFBytes(fs.bytesAvailable));
				oldid = str.match(reg).toString();
				str = str.replace(reg,newid);  
				fs.open(f,FileMode.WRITE);
				fs.writeUTFBytes(str); 
				fs.close();
				
				label.text = newid;
				
				//有多个在运行的程序时只关闭一个运行程序就无法再打开新程序
				//必须监听系统最后一个相同程序关闭时,才能初始化id
				//解决办法:
				//记录运行前id,若为初始ID则在关闭该程序时初始化id,否则不操作
				
				if(oldid == "<id>com.roy</id>")
				{
					this.addEventListener(Event.CLOSE,returnId);
				}
			}
			
			protected function returnId(e:Event):void
			{
				var f:File =new File(File.applicationDirectory.resolvePath(
					"META-INF/AIR/application.xml").nativePath);
				var fs:FileStream = new FileStream();  
				fs.open(f,FileMode.READ);      
				var str:String = new String(fs.readUTFBytes(fs.bytesAvailable));
				str = str.replace(reg,oldid);  
				fs.open(f,FileMode.WRITE);
				fs.writeUTFBytes(str); 
				fs.close();
			}
			
		]]>
	</fx:Script>
	
	<s:VGroup gap="20">
		<s:Label text="已将配置文件id更改为:" color="0xff0000" fontSize="20"/>
		<s:Label id="label" color="0x0000ff" fontSize="20"/>
	</s:VGroup>
</s:WindowedApplication>

 

此程序中配置文件multiapp-app.mxml中,id标签必须为<id>com.roy</id>。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的AT指令程序,用于在Air724UG模块上发送短信: ```c #include <stdio.h> #include <string.h> #include <stdlib.h> #define SERIAL_PORT "/dev/ttyUSB0" // 串口设备名 #define BAUD_RATE 115200 // 波特率 // 打串口设备 int open_serial_port(const char *device, int baud) { int fd = open(device, O_RDWR | O_NOCTTY); if (fd < 0) { perror(device); return -1; } struct termios options; tcgetattr(fd, &options); cfsetispeed(&options, baud); cfsetospeed(&options, baud); options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; tcsetattr(fd, TCSANOW, &options); return fd; } // 发送AT指令并等待响应 int send_at_command(int fd, const char *command, const char *expected_response, int timeout) { char buffer[512]; int len, i; int retries = 3; do { // 发送AT指令 write(fd, command, strlen(command)); write(fd, "\r\n", 2); // 等待响应 memset(buffer, 0, sizeof(buffer)); i = 0; do { len = read(fd, buffer + i, sizeof(buffer) - i); if (len > 0) { i += len; } } while (len > 0 && i < sizeof(buffer) - 1 && !strstr(buffer, expected_response)); // 检查响应是否符合预期 if (strstr(buffer, expected_response)) { return 0; } } while (--retries > 0); return -1; } // 发送短信 int send_sms(int fd, const char *phone_number, const char *message) { char pdu[512]; char command[512]; int i, j, len; // 将消息打包成PDU格式 len = strlen(message); sprintf(pdu, "0011000D91%s0000AA%s", phone_number, message); len = strlen(pdu) / 2; sprintf(pdu, "%02X%s", len, pdu); // 发送AT指令,设置短信中心地址 if (send_at_command(fd, "AT+CSCA=\"+8613800270500\"", "OK", 5000) != 0) { printf("Failed to set SMS center address\n"); return -1; } // 发送AT指令,设置短信发送模式为PDU模式 if (send_at_command(fd, "AT+CMGF=0", "OK", 5000) != 0) { printf("Failed to set SMS mode to PDU\n"); return -1; } // 发送AT指令,发送短信 sprintf(command, "AT+CMGS=%d", strlen(pdu) / 2); if (send_at_command(fd, command, ">", 5000) != 0) { printf("Failed to send SMS command\n"); return -1; } // 发送短信内容 write(fd, pdu, strlen(pdu)); write(fd, "\x1A", 1); // 等待短信发送完成 for (i = 0; i < 10; i++) { memset(command, 0, sizeof(command)); sprintf(command, "AT+CMGS=%d", strlen(pdu) / 2); write(fd, command, strlen(command)); write(fd, "\r\n", 2); j = 0; do { len = read(fd, command + j, sizeof(command) - j - 1); if (len > 0) { j += len; } } while (len > 0 && j < sizeof(command) - 1 && !strstr(command, "+CMGS:")); if (strstr(command, "+CMGS:")) { printf("SMS sent successfully\n"); return 0; } sleep(1); } printf("Failed to send SMS\n"); return -1; } int main() { int fd = open_serial_port(SERIAL_PORT, BAUD_RATE); if (fd < 0) { return -1; } // 在此处填写您的手机号码和短信内容 const char *phone_number = "13800138000"; const char *message = "Hello, World!"; send_sms(fd, phone_number, message); close(fd); return 0; } ``` 此程序实现了在Air724UG模块上发送短信的基本功能。您需要根据您的具体需求修改和扩展此程序。同时请注意,发送短信需要正确配置模块的通信参数和短信中心地址等信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值