Android HAL
2010-04-21 06:36:00 来源:WEB开发网static LedService led_srv;
static Button btn;
static boolean iflag = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("Java App", "OnCreate");
led_srv = new LedService();
Log.i("Java App", "Load Java Serivce");
btn = (Button)this.findViewById(R.id.mybtn);
btn.setonClickListener(this);
}
public void onClick(View v) {
Log.i("Java App", "btnonClicked");
String title = new String();
if (iflag) {
title = led_srv.set_off();
btn.setText("Turn On");
setTitle(title);
iflag = false;
} else {
title = led_srv.set_on();
btn.setText("Turn Off");
setTitle(title);
iflag = true;
}
}
}
LedService.java 文件:
package com.hello.LedService;
import android.util.Log;
public final class LedService {
/*
* load native service.
*/
static {
Log.i ( "Java Service" , "Load Native Serivce LIB" );
System.loadLibrary ( "led_runtime" );
}
public LedService() {
int icount ;
Log.i ( "Java Service" , "do init Native Call" );
_init ();
icount = _get_count ();
Log.d ( "Java Service" , "Init OK " );
}
/*
* LED native methods.
*/
public String set_on() {
Log.i ( "com.hello.LedService" , "LED On" );
_set_on ();
return "led on" ;
}
public String set_off() {
Log.i ( "com.hello.LedService" , "LED Off" );
更多精彩
赞助商链接