Android STK服务详解:消息处理与功能应用

需积分: 20 127 下载量 121 浏览量 更新于2024-08-13 收藏 158KB PPT 举报
本文档主要解析了Android系统中的StkService(STK Service),它是专为SIM Toolkit(STK)功能设计的服务组件。STK是一种嵌入在SIM卡中的Java平台应用,它提供了一组命令和接口,使得SIM卡能处理短信数据并执行自定义的应用程序,如金融交易、信息服务等。 在StkService的实现流程中,关键部分包括以下几个环节: 1. handleMessage:这是服务的核心入口,负责转发RIL(Radio Interface Layer,无线接口层)接收到的消息至Decoder,这是一个上行数据流处理器,用于解码和处理来自网络的数据。 2. Decoder处理:Decoder接收到RIL的消息后,会对数据进行相应的解析和处理,然后将结果返回给handler,进一步进行后续操作。 3. handleRilMsg:这是上行数据流的出口,处理来自Decoder的最终结果,并可能触发相应的行为,如发送终端响应或者执行预置的命令。 4. handleProactiveCommand:在某些情况下,服务会主动发送命令给终端,比如回应用户的菜单选择或执行特定任务。 5. sendTerminalResponse和sendMenuSelection:这两个方法用于向终端发送响应或菜单选择,确保用户界面的交互顺畅。 6. onCmdResponse:这是一个继承自AppInterface的下行接口,当应用程序接收到服务器的命令响应时,会通过这个接口通知StkService,以便进行下一步处理。 7. CmdIf.sendTerminalResponse和CmdIf.sendEnvelope:这两个方法用于发送终端响应,封装了向外部应用发送数据的逻辑。 8. handleSessionEnd:当会话结束时,StkService会清理相关资源,确保服务的正确关闭。 STK技术的应用场景广泛,尤其是在金融领域,如手机银行、股票交易等,通过简化用户操作,提供方便快捷的增值服务。STK卡因其内置应用程序和较高的存储容量,与传统SIM卡相比,具备更多的互动性和功能扩展性。 总结来说,StkService在Android中扮演着至关重要的角色,它实现了SIM卡与手机应用之间的通信,提供了用户友好的交互方式,使得基于STK的增值业务得以实现。通过解析这个服务,开发者可以更好地理解和利用STK技术为用户提供创新的移动服务体验。

将一下java代码转成c语言:import java.util.; public class Main { public static boolean judge(char c1,char c2) { char ch[] = {'#','+','-','','/','%','(',')'}; int num1 = 0,num2 = 0; for(int i = 0;i <= 7;i ++) { if(ch[i] == c1) num1 = i; if(ch[i] == c2) num2 = i; } if(num1 > num2) return true; return false; } public static int calculation(int t1,int t2,char c) { if(c == '+') return t2 + t1; else if(c == '-') return t2 - t1; else if(c == '*') return t2 * t1; else if(c == '%') return t2 % t1; else return t2 / t1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); Stack<Integer> stk_int = new Stack<>(); Stack<Character> stk_str = new Stack<>(); int index = 0; stk_str.push('#'); for(int i = 0;i < s.length();i ++) { if(s.charAt(i) < '0' || s.charAt(i) > '9') { if(index != i) stk_int.push(Integer.parseInt(s.substring(index,i))); index = i+1; boolean flag = false; while(flag == false) { if (judge(s.charAt(i),stk_str.peek())) { stk_str.push(s.charAt(i)); if(stk_str.peek() == '(' ) stk_str.push('#'); if( stk_str.peek() == ')') { stk_str.pop(); while(stk_str.peek()!='#') { stk_int.push(calculation(stk_int.pop(),stk_int.pop(),stk_str.pop())); } stk_str.pop(); stk_str.pop(); } flag = true; } else { stk_int.push(calculation(stk_int.pop(),stk_int.pop(),stk_str.pop())); } } } if(index != s.length() && i == s.length()-1) stk_int.push(Integer.parseInt(s.substring(index,s.length()))); } while(!stk_int.isEmpty() && stk_str.peek()!= '#') { stk_int.push(calculation(stk_int.pop(),stk_int.pop(),stk_str.pop())); } System.out.println(stk_int.pop()); } }

2023-05-28 上传