Android HAL 开发 (4)

来源:互联网 发布:360度全景软件 编辑:程序博客网 时间:2024/06/06 07:40
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://buaadallas.blog.51cto.com/399160/371560

 在上一篇文章中,我们看到了如果在java程序中调用C/C++撰写的函数。而且Android的service已经实现了,下面就要看看应用程序如何调用这个service了,这里用两种方法,我们先介绍简单的第一种直接调用方法。

apps/mokoid/apps/LedClient/src/com/mokoid/LedClient/LedClient.java

  1. package com.mokoid.LedClient; 
  2. import com.mokoid.server.LedService; 
  3.  
  4. import android.app.Activity; 
  5. import android.os.Bundle; 
  6. import android.widget.TextView; 
  7.  
  8. public class LedClient extends Activity { 
  9.     @Override 
  10.     public void onCreate(Bundle savedInstanceState) { 
  11.         super.onCreate(savedInstanceState); 
  12.  
  13.         // Call an API on the library. 
  14.     LedService ls = new LedService(); 
  15.     ls.setOn(1); 
  16.     ls.setOff(2); 
  17.          
  18.         TextView tv = new TextView(this); 
  19.         tv.setText("LED 1 is on. LED 2 is off."); 
  20.         setContentView(tv); 
  21.     } 

上面的代码很简单,直接调用上一篇文章介绍的LedService,然后利用这个service的成员函数setOn和setOff直接操作硬件(通过jni->HAL)。

原创粉丝点击