AlanZhang

Integrate a new hardware into Android (3) -blog archive

Discussion created by AlanZhang Employee on Oct 9, 2011
Latest reply on Oct 13, 2011 by Daiane Angolini

Now, let's come to the implementation of LED Service Entity that is resided in Framework layer. For legacy architecture, the LED Service Entity is quite straightforward. The LED Service Entity code is resided in frameworks/base/service/java/com/mokoid/server/LedService.java.

106-LegacyService.png

 

 

Application Test Code

The test code is resided in apps/LedClient/src/com/mokoid/LedClient/LedClient.java as following:

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

Outcomes